On Dec 1, 2008, at 1:41 PM, Anton Ertl wrote:
Dennis Ruffer wrote:
On Nov 29, 2008, at 3:42 AM, Anton Ertl wrote:
Dennis Ruffer wrote:
Here's yet another puzzle for the interface semantics:
err = (*iodev)->QueryInterface(iodev, CFUUIDGetUUIDBytes
(kIOUSBDeviceInterfaceID), (LPVOID)&dev);
Does this have anything to do with the function pointers
described in
the docs, or is this something else entirely?
Yes, this looks like a call through a function pointer.
Thanks for the answers Jack and Anton, here's what I've got so far:
err = (*dev)->Release(dev);
becomes:
\c typedef long (* func1)(void*);
\c #define call_func1(par1,fptr) ((func1)fptr)(par1)
c-function call_func1 call_func1 a func -- n
begin-structure IUNKNOWN_C_GUTS
field: reserved
field: QueryInterface \ a a a -- n
field: AddRef \ a -- n
field: Release \ a -- n
end-structure
dev @ dup @ Release @ call_func1 .
However, with QueryInterface, I need to figure out what
CFUUIDGetUUIDBytes is doing
It is defined as:
typedef struct {
...
} CFUUIDBytes;
/* The CFUUIDBytes struct is a 128-bit struct that contains the
raw UUID. A CFUUIDRef can provide such a struct from the
CFUUIDGetUUIDBytes() function. This struct is suitable for
passing to APIs that expect a raw UUID.
*/
CFUUIDBytes CFUUIDGetUUIDBytes(CFUUIDRef uuid);
However, I can't figure out any thing to put in the return value to
prevent errors.
Structs as return values (or as parameters) are not yet supported by
the libcc interface, but one can work around that (see below).
c-function CFUUIDGetUUIDBytes CFUUIDGetUUIDBytes a -- a
gives me:
/Users/druffer/.gforth/libcc-tmp/gforth_c_103DF4C.c:11: error:
aggregate value used where an integer was expected
What is an aggregate return value?
A struct or a union.
There are several workarounds possible.
- If you always want to use QueryInterface with the CFUUIDGetUUIDBytes
call as second parameter, just put the call in the macro for the
QueryInterface call.
- OTOH, if you want to do the CFUUIDGetUUIDBytes call at the Forth
level, you have to work around the inability to return a struct and
around the inability to pass a struct. A way to do this is to create
your own buffer for a temporary CFUUIDBytes struct, and pass a pointer
to this struct to a CFUUIDGetUUIDBytes macro and a QueryInterface
macro. These macros would have to do any dereferencing or somesuch
themselves, e.g.:
\c #define CFUUIDGetUUIDBytes1(uuid,res) (*(CFUUIDBytes *)(res) =
CFUUIDGetUUIDBytes((CFUUIDRef)uuid)
c-function CFUUIDGetUUIDBytes1 CFUUIDGetUUIDBytes1 a a -- void
\c #define call_QueryInterface(f,x,y,z) (((functype)f)(x,*
(CFUUIDBytes *)y,z))
c-function call-QueryInterface func a a a -- n
and call it like:
create CFUUIDBytesbuf 16 allot
uuid1 CFUUIDBytesbuf CFUUIDGetUUIDBytes1
iodev1 QueryInterface @ iodev1 CFUUIDBytesbuf devbuf call-
QueryInterface
or something along these lines.
- anton
The 1st option sounds the best, but my first attempts didn't get it.
So, I'll try more tonight.
DaR
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]