FFI Variables

Andreas Raab Andreas.Raab at gmx.de
Sun Apr 21 20:20:06 UTC 2002


You must use either "byte*" or "void*" instead of "char*". This is
because "char*" declarations are assumed to be string parameters and
strings in C are zero terminated whereas in Squeak they are not. Because
of this, all strings passed into C function calls are allocated on the C
heap before passing them out to the function. And, to avoid the
overhead, these strings are not copied back into their Squeak
representation once the function call has completed. Thus, if you have
any function that should modify a string in place you must not declare
it as "char*".

  - Andreas

> -----Original Message-----
> From: squeak-dev-admin at lists.squeakfoundation.org 
> [mailto:squeak-dev-admin at lists.squeakfoundation.org] On 
> Behalf Of Norberto Manzanos
> Sent: Sunday, April 21, 2002 10:05 PM
> To: squeak-dev at lists.squeakfoundation.org
> Subject: FFI Variables
> Thanks to Martin McClure I could create some FFI classes.
> But there's a item I still don't understand
> Whe you have a DLL function that returns not only the 
> function value but a 
> var parameter indeed, how can I access it from Squeak?
> This is the case:
> apiIsisRecField: aHandle at: index tag: aTag occ: nOcc field: 
> cField long: 
> lField
> 	<apicall: long 'IsisRecField' (long long long long 
> char* long) module: 
> 'isis32.dll'>
>       ^self externalCallFailed
> In Delphi, for example, I can call this function that way:
> Var s:PChar;
> r,handle,tag,nOcc,lField: LongInt;
> //give some values to the variables and allocate PChar (Uff!!!!)
> r:= IsisRecField(handle,tag,nocc,s,lfield);
> // and s is the value I really need, r is not very important, 
> but the FFI 
> class give this value

More information about the Squeak-dev mailing list