Re: Reference-return
Well, thanks. It seems logical, but in fact it doesn't work for me.
If I declare the foreign-function with the argument (outData
(:reference-return Uint32)) the result is perfectly normal...
But if I do the same with (outData (:reference-return (:pointer :void)))
get the pointer and than do : (dereference thisPointer :type :int)
LW crashes, with a error message of type :
"signal A [code 0] at 20671181 {inside #<Function ((TOP-LEVEL-FORM 22) . 1)
20671172>}
Eax 0;ebx 0;ecx 200;edx 16C esp21385830;esb2138587C;esi EB;edi EB"
In this case (it seems to be the problem even if I don't understand exactly)
the void pointer returned by the function has the address of the number I
need... (if this number is zero the pointer is a null pointer...).
So, with fli:pointer-adress I can get it (but this works only for unsigned
integer, naturally)
Denis
Le 20/10/06 17:51, « [NOM] » <[ADRESSE]> a écrit :
> On Friday 20 October 2006 10:46 am, Denis Pousseur wrote:
>> This argument is declared in the header of the C source code as: *void
>> outData, .
>
> If I understood your question correctly, I think that you want to declare the
> return type as
>
> (outData (:reference-return (:pointer :void)))
>
> just like the C header, and then use fli:dereference using the :type keyword
> (to "coerce" the pointer to a different type).
>
> Then, your program logic must determine which type is being returned and
> coerce the void* appropriately (maybe in a "case" statement).
>
> Here is a small sample:
>
> ;; create a foreign object, like the one which
> ;; might be returned from a C function
> (setq intp (fli:allocate-foreign-object :type :int))
> (setf (fli:dereference intp) 12)
> ;; check that it dereferences correctly
> (fli:dereference intp)
>
> ;; create a void*
> (setq voidp (fli:allocate-foreign-object :type '(:pointer :void)))
>
> ;; put the address of the above int into the void*, which is
> ;; how C will return it (an int*, put inside a void*)
> (setf (fli:pointer-address voidp) (fli:pointer-address intp))
>
> ;; coerce the void* to an int and dereference it
> ;; the answer should be 12
> (fli:dereference voidp :type :int)
>
> The above, translated into C looks kind of like this:
>
> int* intp;
> *intp = 12;
> printf ("%d\n", *intp);
> void* voidp;
> voidp = intp;
> printf ("%d\n", *(int*)voidp);
>
> If it's still not clear, feel free to ask me for more help.
> pt
>
-------------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles, Belgique
Tel : 32 (0)2 219 31 09
Mail : denis.pousseur@compositeurs.be
Website : http://compositeurs.be/pousseur
-------------------------------------------------------