Help with FFI structure pointer

Ron Teitelbaum Ron at USMedRec.com
Tue Aug 1 20:56:15 UTC 2006


Thanks Nicolas,

That was a very good suggestion.  I should have realized that the pointer
could be used on the structure.  I saw the comment about accessing external
structures through the primitive if the handle is external address.  

I tried it and got some odd results.  The handle came back as zero.  Trying
to access the data at zero was ineffective as expected, but freeing the
context using the zero pointer didn't blow up!

I feel like I'm walking through a strange room blindfolded.  

I do get data results if I use the structure as the return instead of the
pointer.  Looking at the data it appears that I've done something wrong in
fields, so I'm going to double check that.

Also when I tried using MyStruct * as the parameter sending nil came back
with can not coerce arguments.  

Thanks for the suggestion it was a good tip!  

Ron

> -----Original Message-----
> From: squeak-dev-bounces at lists.squeakfoundation.org [mailto:squeak-dev-
> bounces at lists.squeakfoundation.org] On Behalf Of nicolas cellier
> Sent: Tuesday, August 01, 2006 4:05 PM
> To: squeak-dev at lists.squeakfoundation.org
> Subject: Re: Help with FFI structure pointer
> 
> I do not understand how this code works.
> 
> If external code is allocating the structure, shouldn't it return a
> pointer to
> the structure rather than a structure by value, what i understand as a
> copy?
> 
> Wouldn't it be
> 
> <apicall: MyStruct * 'MyAPICall' (MyStruct *) module: 'my.dll'>
> 
> In which case, you can pass nil to the pointer and have a single MyApiCall
> declared in Smalltalk.
> 
> If MyStruct is just an opaque handle you do not access but thru external
> code,
> maybe you can write:
> 
> <apicall: long 'MyAPICall' (long) module: 'my.dll'>
> <apicall: void 'FreeContext' (long) module: 'my.dll'>
> 
> Nicolas
> 
> Le Mardi 01 Août 2006 21:30, Ron Teitelbaum a écrit :
> > All,
> >
> > I'm sure someone saw this coming.  I could use some help.
> >
> > Ok I built a structure but the use of the structure is kinda odd.
> >
> > What I need to do is pass the structure in as null for the first call.
> Then
> > I need to pass the real structure in for subsequent calls.
> > Finally I need to free the structure through the API using the structure
> > pointer.
> >
> > I handled the first two problems by implementing
> >
> > <apicall: MyStruct 'MyAPICall' (long) module: 'my.dll'>  and sending in
> > nil. And
> > <apicall: MyStruct 'MyAPICall' (MyStruct) module: 'my.dll'>  <- this is
> so
> > cool!  I assume that Andreas wrote this code, it is beautiful!
> >
> > Ok now here it the problem:
> >
> > I have to call
> >
> > <apicall: void 'FreeContext' (MyStruct *) module: 'my.dll'>  or
> something.
> >
> > The pointer needs to be sent to the apicall.  Did I do this correctly
> > (using MyStruct *) and it just doesn't work or is there another way to
> get
> > the handle of the structure.  The structure itself has a handle ivar but
> > it's a byteArray.
> >
> > The result using MyStruct * is:
> > ---------------------------------------------------------------------
> > Tue Aug 01 14:28:54 2006
> >
> > Exception code: C0000005
> > ============
> > which appears to be a buffer overrun:
> > // MessageId: STATUS_ACCESS_VIOLATION
> > //
> > // MessageText:
> > //
> > //  The instruction at "0x%08lx" referenced memory at "0x%08lx". The
> memory
> > could not be "%s".
> > //
> > #define STATUS_ACCESS_VIOLATION          ((NTSTATUS)0xC0000005L)    //
> > winnt ============
> > Exception addr: 77A8CE7E
> > Access violation (read access) at 0000000D
> > EAX:000C04E0 EBX:7C809794 ECX:00000000 EDX:00000001
> > ESI:00000001 EDI:000C04E0 EBP:0006FB80 ESP:0006FB74
> > EIP:77A8CE7E EFL:00210202
> > FP Control: FFFF037F
> > FP Status:  FFFF4000
> > FP Tag:     FFFFFFFF
> > VM Version: Squeak 3.7.1 (release) from Sep 23 2004
> > Compiler: gcc 2.95.2 19991024 (release)
> >
> > Current byte code: 225
> > Primitive index: 120
> >
> > Loaded plugins:
> >  SoundGenerationPlugin 23 September 2004 (i)
> >  SoundPlugin 23 September 2004 (i)
> >  crypt32.dll
> >  SqueakFFIPrims 23 September 2004 (e)
> >  ZipPlugin 23 September 2004 (i)
> >  SocketPlugin 23 September 2004 (i)
> >  DSAPrims 23 September 2004 (i)
> >  UUIDPlugin 23 September 2004 (i)
> >  LargeIntegers v1.3 23 September 2004 (i)
> >  Matrix2x3Plugin 23 September 2004 (i)
> >  FloatArrayPlugin 23 September 2004 (i)
> >  B2DPlugin 23 September 2004 (i)
> >  BitBltPlugin 23 September 2004 (i)
> >  SecurityPlugin 23 September 2004 (i)
> >  FilePlugin 23 September 2004 (i)
> >  MiscPrimitivePlugin 23 September 2004 (i)
> >
> >
> > Stack dump:
> >
> > 619600144 Win32FFICertificateStore>freeCertContext
> > 619599740 Win32FFICertificateStore>?
> > .
> >
> > Thank you for any help!
> >
> > Ron Teitelbaum
> 
> 





More information about the Squeak-dev mailing list