• ExternalStructure with pointer to functions

    From Udo Schneider@21:1/5 to All on Wed Nov 13 12:34:21 2019
    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

    Am 12.10.2019 um 15:44 schrieb Dima Smirnov:
    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?


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dima Smirnov@21:1/5 to All on Sat Dec 7 20:38:20 2019
    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'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)