I've got a working MonoTouch binding for ZBar up and running, but am having troubles exposing a constant NSString that the Obj-C library defines for use as a Key in an NSDictionary:
inside ZBarReaderController.h:
extern NSString* const ZBarReaderControllerResults;
I first tried via the actual MonoTouch binding as documented here:
[Static]
interface ZBarSDK
{
[Field ("ZBarReaderControllerResults")]
NSString BarcodeResultsKey { get; }
}
Attempting to build the project containing this gave these errors from btouch:
Unhandled Exception: System.ArgumentOutOfRangeException: Argument is out of range.
Parameter name: startIndex
at System.String.Substring (Int32 startIndex) [0x00000] in :0
at Generator.Generate (System.Type type) [0x00000] in :0
at Generator.Go () [0x00000] in :0
at BindingTouch.Main (System.String[] args) [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentOutOfRangeException: Argument is out of range.
Parameter name: startIndex
at System.String.Substring (Int32 startIndex) [0x00000] in :0
at Generator.Generate (System.Type type) [0x00000] in :0
at Generator.Go () [0x00000] in :0
at BindingTouch.Main (System.String[] args) [0x00000] in :0
I next attempted to manually call into the code as suggested in this other SO answer.
public static NSString BarcodeResultsKey
{
get
{
var libHandle = Dlfcn.dlopen("libzbar.a",0);
// I also tried this with "__Internal", rather than "libzbar.a"
return Dlfcn.GetStringConstant(libHandle, "ZBarReaderControllerResults");
}
}
It builds and executes fine, but just returns an empty string (as the Dlfcn.GetStringConstant documents it will do if it fails to link).
So, anyone else accessed const strings from a 3rd party Obj-C library?