Re: [Pharo-users] uFFI ExternalAddress challenges
OK, great, I'll try it out. Thanks, Tomaz ------ Original Message ------ From: "Guillermo Polito" <guillermopolito@gmail.com> To: "Tomaž Turk" <tomaz.turk@ef.uni-lj.si> Sent: 17.9.2019 11:56:21 Subject: Re: [Pharo-users] uFFI ExternalAddress challenges
I donât know if there is support for that (I donât have the time to check it in detail now). But, as a workaround, you may try
- return a void*
myFunction ^self ffiCall: #(void* myFunction ( void ) )
- and then do the transformation yourself using Win32WideString>>#fromHandle:
Tomaž Turk <tomaz.turk@ef.uni-lj.si> wrote:
OK, great, I'll try it out.
Hi Tomaž, What you are discovering here would be very useful as a section/chapter in the uFFI booklet. Just posting it as text here will do if you donât feel up to translating to Pillar. Cheers Stephan
Hi,
I donât know if there is support for that (I donât have the time to check it in detail now). But, as a workaround, you may try
- return a void*
myFunction ^self ffiCall: #(void* myFunction ( void ) )
- and then do the transformation yourself using Win32WideString>>#fromHandle:
I checked, Win32WideString class>>#asExternalTypeOn: is defined, and it creates FFIExternalObjectType(Win32WideString) nicely with ^self ffiCall: #(Win32WideString myFunction ( void ) ) I also tried the other approach: ^self ffiCall: #(void* myFunction ( void ) ) and the transformation Win32WideString>>#fromHandle Interestingly, in both cases I get however I cannot pinpoint the reason for this.
What you are discovering here would be very useful as a section/chapter in the uFFI booklet.
Thanks for the invitation, yes, it would be nice to participate, I'll try to prepare something when I get to the bottom of the challenge :-) Thanks and best wishes, Tomaz
Hi, after some more investigation the easiest way to get Win32WideString from external module is to pass it as a parameter, like in: ^self ffiCall: #( void myFunction ( Win32WideString aWin32WideString ) ) and the external module can access it directly to do r/w. There are other possibilities as well - like adapting the method Win32WideString>>#fromHandle: to translate from ExternalData to Win32WideString, creating new ExternalType, or even creating a new FFIWin32WideString. I wonder what would be the best approach :-) Best wishes, Tomaz -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Hi, as a wrap-up for this forum thread, I found an elegant way to take a result as C wchar_t* from an FFI call on Windows, based on the idea of ExternalData>>#fromCString. If anybody needs it: https://github.com/eftomi/pharo-uFFI-readWin32WideString. Best wishes, Tomaz -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
participants (3)
-
eftomi -
Stephan Eggermont -
Tomaž Turk