Note that there are some explanatory texts on larger screens.

plurals
  1. POC Callback in Objective-C (IOKIT)
    primarykey
    data
    text
    <p>I am trying to write some code that interacts with an USB device in Objective C, and I got stuck on setting the callback function for incoming reports. In my case it's an IOKIT function but I think the problem is more general as I (apparently) don't know how to correctly set a C callback function in Objective-C. I've got a Class "USBController" that handles the io functions</p> <p>USBController.m: </p> <pre><code>#include &lt;CoreFoundation/CoreFoundation.h&gt; #include &lt;Carbon/Carbon.h&gt; #include &lt;IOKit/hid/IOHIDLib.h&gt; #import "USBController.h" static void Handle_IOHIDDeviceIOHIDReportCallback( void * inContext, // context from IOHIDDeviceRegisterInputReportCallback IOReturn inResult, // completion result for the input report operation void * inSender, // IOHIDDeviceRef of the device this report is from IOHIDReportType inType, // the report type uint32_t inReportID, // the report ID uint8_t * inReport, // pointer to the report data CFIndex InReportLength) // the actual size of the input report { printf("hello"); //just to see if the function is called } @implementation USBController - (void)ConnectToDevice { ... IOHIDDeviceRegisterInputReportCallback(tIOHIDDeviceRefs[0], report, reportSize, Handle_IOHIDDeviceIOHIDReportCallback,(void*)self); ... } ... @end </code></pre> <p>All the functions are also declared in the header file.</p> <p>I think I did pretty much the same as what I've found <a href="https://stackoverflow.com/questions/316879/handling-callbacks-in-objective-c/" title="here">here</a>, but it doesn't work. The project compiles nicely and everything works up till the moment there is input and the callback function is to be called. Then I get an "EXC_BAD_ACCESS" error. The first three arguments of the function are correct. I'm not so sure about the context.. What did I do wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload