I'm doing an asynchronous read from a USB printer. The read works correctly. My trouble is updating a NSTextField from within the callback.
> -(IBAction)printTest:(id)sender > { …. > NSLog(@"starting async read: %@", _printerOutput); > NSLog(@"_printerOutput pointer = %p", _printerOutput); > > result = (*interface)->ReadPipeAsyncTO(interface, > 1, > readBuffer, > numBytesRead, > 500, > 1000, > > USBDeviceReadCompletionCallback, > &(_printerOutput) > ); The callback is defined as: > void USBDeviceReadCompletionCallback(void *refCon, IOReturn result, void > *messageArg) > { > NSTextField *printerOutput = (__bridge NSTextField *) messageArg; > NSLog(@"_printerOutput pointer = %p", printerOutput); > } The pointer loses its value when inside of the callback. 2013-04-08 16:36:25.348 MyUSB[8120:303] starting async read: <NSTextField: 0x10221dc60> 2013-04-08 16:36:25.348 MyUSB[8120:303] _printerOutput pointer = 0x10221dc60 2013-04-08 16:36:27.166 MyUSB[8120:303] _printerOutput pointer = 0x0 I've looked in many places trying to mimic different ways to pass in the pointer. There can be only one correct way. :) Another variation on the theme: (__bridge void *)(_printerOutput). This doesn't work, either. I understand that the callback is of type IOAsyncCallback1. Other URLs of note: http://www.google.com/search?client=safari&rls=en&q=another+usb+notification+example&ie=UTF-8&oe=UTF-8 http://stackoverflow.com/questions/8010382/updating-ui-from-a-c-function-in-a-thread Thank you for reading. Caylan _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com