Hi,

I think what you want to do is change this:

[BaseType (typeof(NSObject))]
interface TcpPrinterConnection : ZebraPrinterConnection

to this:

[BaseType (typeof(ZebraPrinterConnection))]
interface TcpPrinterConnection

On Wed, Jun 13, 2012 at 4:19 AM, Дмитрий Надеждин <denadezh...@gmail.com>wrote:

> Dear MonoTouch subscribers,
>
> The same question is here:
> http://stackoverflow.com/questions/11008726/binding-of-zebra-sdk-to-monotouch
>
> Short version: I have created a binding for Zebra native library for
> mobile printers and the basic functionality works fine (wireless connection
> between the printer and the iPad, writing data to streams, printing out
> text, etc.)
> I want to print out PDFs and images, and the native library provides the
> classes for that. However, I can't get it to work from Monotouch.
>
>
> Long version: I have problem binding the structure described below.
>
> @protocol ZebraPrinterConnection
>     - (BOOL) open;
>     - (void) close;
>     - (NSInteger) write:(NSData *)data error:(NSError **)error;
>     - (NSData *)read: (NSError**)error;
>
> @interface TcpPrinterConnection : NSObject<ZebraPrinterConnection> {
>      some @private properties
> }
>      - (id)initWithAddress:(NSString *)anAddress andWithPort:(
> NSInteger)aPort;
>
> @interface ZebraPrinterFactory : NSObject { }
>   +(id<ZebraPrinter,NSObject>) getInstance:(id<ZebraPrinterConnection,
> NSObject>) connection error:(NSError**)error
>
>
> The tricky part here is to obtain ZebraPrinter instance in Monotouch code.
> Note how ZebraPrinterFactory wants ZebraPrinterConnection to be passed to
> it, but onlyTcpPrinterConnection has an actual constructor.
> The connection classes work fine when bound like this:
>
> [BaseType (typeof (NSObject))]
> [Model]
> interface ZebraPrinterConnection
> {
>
> [Export ("open")] bool Open();
>
> [Export ("close")] void Close();
> [Export ("write:error:")] int Write(NSData data, out NSError error);
> [Export ("read:")] NSData Read(out NSError error);
>
> }
>
> [BaseType (typeof(NSObject))]
> interface TcpPrinterConnection : ZebraPrinterConnection
> {
>
> [Export ("initWithAddress:andWithPort:")] IntPtr Constructor (string
> anAddress, int aPort);
>
> }
>
> Binding of ZebraPrinterFactory class is not as straightforward. If I bind
> it like this:
>
> [BaseType (typeof(NSObject))]
> interface ZebraPrinterFactory
> {
>
> [Static, Export ("getInstance:error:")]
>
> ZebraPrinter getInstance(ZebraPrinterConnection connection, out NSError
> error);
>
> }
>
> then I try to use something like
>
> myConn = new TcpPrinterConnection(ipAddress, port);
> myConn.Open ();
> ZebraPrinter zPrinter = ZebraPrinterFactory.GetInstance(myConn, out err);
> // compile-time error: Cannot convert TcpPrinterConnection
> into ZebraPrinterConnection
>
> I get a compile-time error. If I change the binding for Mono to
> accept TcpPrinterConnection as parameter (I've tried multiple
> configurations), I get runtime exception ("System.InvalidCastException:
> Cannot cast from source type to destination type.") which has no inner
> exceptions and I have no idea which type could not be converted (strongly
> suspecting that same conversion as above).
> It's really frustrating having something ALMOST working, but not quite.
>
> Any ideas? I'm starting to think of binding limitations already. Could
> someone tell me if such structures can be bound at all?
>
> Regards, Dmitry
>
> _______________________________________________
> MonoTouch mailing list
> MonoTouch@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
_______________________________________________
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to