On 2/22/2023 7:35 AM, Ashok wrote:
On 2/21/2023 11:25 PM, Jacob wrote:
I figured it out. I needed to convert to and from binary. I used the
following functions from Arjen:
Jacob,
You haven't shown what you do with those generated binaries but be aware
that if your function is in fact treating those array parameters as
in-out (as you have shown in your CFFI definition), then it will write
to the storage allocated by the Tcl_Obj. This is generally a no-no. If
they are input parameters only then that should be ok.
For output and inout parameters, you probably have to explicitly
allocate memory in ffidl. I'm not sufficiently familiar with ffidl to
know how to do that.
/Ashok
Ashok,
Thank you for your feedback. As far as I can tell things are working
correctly, but I would not be surprised if there is something dangerous
I'm doing. Here is the code for completeness. This function in the dll
file is a little strange in that it does have many in-out parameters,
but only one is actually relevant to me (rresp). Considering the script basically ends here and tcl closes, hopefully whatever risky behavior
going on behind the scenes can be ignored.
# current script location
set scriptFolder [file dirname [info script]]
# load ffid package
load [file join $scriptFolder Ffidl07t.dll]
# setup dll call
set DLL [file join $scriptFolder myFunc.dll]
set typeList {pointer-var pointer-var pointer-var pointer-var
pointer-var pointer-var pointer-var pointer-var pointer-utf8}
ffidl::callout myFunc $typeList long [ffidl::symbol $DLL myFunc]
# initialize inputs
set iparam {1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1}
set nparam 30
set iresp {1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1}
set rresp {1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1}
set dresp {1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1}
set nresp 1
set isens 0
set userdata U
Binarize i iparam nparam iresp nresp isens
Binarize d dresp rresp rparam
set rparam {7 0.00018 -45.2107 0.39324 32.5714 -4.82 0.536 207.8 99.6 \
-20.7 12 10 100 3 0 0 -2 -3 1 17 0.00018181 -10.1909 -3.3898 29.2007 \
0.26492 0.29827 0.4567 0.00428 0.0077969 -0.039173}
myFunc iparam rparam nparam iresp rresp dresp nresp isens userdata
deBinarize d rresp
set resp [lindex $rresp 0]
puts "Response: $resp"
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)