Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ExternalStructure with pointer to functions

99 views
Skip to first unread message

Dima Smirnov

unread,
Oct 12, 2019, 9:44:19 AM10/12/19
to
Hello! How can I describe a similar structure:

typedef struct _ISciterAPI {
UINT version; // is zero for now

LPCWSTR SCFN( SciterClassName )();
UINT SCFN( SciterVersion )(BOOL major);
} ISciterAPI;

in Dolphin?

Udo Schneider

unread,
Nov 13, 2019, 6:34:23 AM11/13/19
to
Can't give you code - but I did this a few years back.

Create an external library and add an method with a call signature
matching the function you got below.

Then you need to get the ExternalMethod instance (e.g. UserLibrary
methodDictionary at: #blockInput:). This ExternalMethod instance
contains and ExternalDescriptor which contains the (for DLLs resolved)
proc address (check for #procAddress). You need to write the address you
got below into the descriptor literal. Then you can call the function
you got below by using an instance of your own lib. I /think/ there was
also some lazy/caching stuff going on. You might have to check.

Can't give you the exact code. But this is the rough outline.

CU,

Udo

Dima Smirnov

unread,
Dec 7, 2019, 11:38:22 PM12/7/19
to
Thank you, Udo, for your answer.
I got the following code, I don’t know how correct it is,but it works :)

ExternalStructure subclass: #SCITERAPI
SCITERAPI class >> defineFields
self
defineField: #version type: WORDField new; "UINT version; // is zero for now"
defineField: #SciterClassName type: INT_PTRField new ;
defineField: #SciterVersion type: INT_PTRField new …


ExternalLibrary subclass: #SciterLibrary
instanceVariableNames: 'api'
SciterLibrary >> api
api := self SciterAPI.
^api

SciterLibrary >>SciterAPI
"Private - SciterAPI_ptr sciterAPI = (SciterAPI_ptr) GetProcAddress(hm, SciterAPI);"

<stdcall: SCITERAPI* SciterAPI>
^self invalidCall

SciterLibrary >> SciterClassName
| val |
val := self
runSciterMethod: 's <stdcall: byte* _ >'
address: api SciterClassName
arguments: #().
^Utf16String fromAddress: val

SciterLibrary >> runSciterMethod: aSource address: anAddress arguments: anArgs
| method val |
method := Compiler compile: aSource in: Object.
method descriptorLiteral dwordAtOffset: 0 put: anAddress.
val := method value: self withArguments: anArgs.
^val

And an example of use:
sc:= SciterLibrary default.
sc api.
sc SciterClassName. -> 'H-SMILE-CHILD'
0 new messages