[cffi-devel] Passing address of pointer
Frank Goenninger
frgo at me.com
Thu Aug 25 17:19:41 UTC 2011
Hi all,
I have a C struct as follows:
(defcstruct MyPrivateData
(notification io_object_t)
(deviceInterface :pointer) ;; void pointer
(deviceName CFStringRef)
(locationID UInt32))
of which the deviceInterface slot is the one I'm interested in. I need to pass the address of the deviceInterface pointer to a function that sets the pointer to valid device interface struct.
So...
In the sample code from Apple the C function is called like this:
typedef struct MyPrivateData {
io_object_t notification;
IOUSBDeviceInterface **deviceInterface;
CFStringRef deviceName;
UInt32 locationID;
} MyPrivateData;
IOCFPlugInInterface **plugInInterface = NULL;
SInt32 score;
HRESULT res;
res = (*plugInInterface)->QueryInterface( plugInInterface,
CFUUIDGetUUIDBytes( kIOUSBDeviceInterfaceID ),
(LPVOID*) &privateDataRef->deviceInterface );
How would I translate this call into a valid CFFI equivalent ?
I have so far:
(let ((query-interface-ptr
(foreign-slot-value plugInInterface
'IOCFPlugInInterface
'ccag.osx.iokit::QueryInterface)))
(format *debug-io* "~%DEVICE-ADDED: query-interface-ptr = ~s."
query-interface-ptr)
(setq res (foreign-funcall-pointer
query-interface-ptr
()
:pointer plugInInterface
CFUUIDBytes (cf-uuid-get-uuid-bytes
kIOUSBDeviceInterfaceID)
:pointer (foreign-slot-pointer privateDataRef
'MyPrivateData
'deviceInterface)))
(format *debug-io* "~%DEVICE-ADDED: deviceInterface = ~s."
(foreign-slot-value privateDataRef 'MyPrivateData 'deviceInterface))
...
This code "crashes" with signal 100 as reported by AllegroCL in the call to foreign-funcall-pointer ...
Any hints or advice really appreciated!
TIA!
Best wishes
Frank
More information about the cffi-devel
mailing list