Re: C++/TCL Need Solution to Compile Error c2784



Alexandre Ferrieux wrote:
On Apr 13, 10:51 pm, David Gravereaux <davyg...@xxxxxxxxx> wrote:
Christian Gollwitzer wrote:
SWIG does its job very well. For a first approximation, you can probably
just pass the headerfile into it like
swig -tcl8 -c++ headerfile.h
I'll put $100 down that the time it takes Jesus to get the time saving tools to
work, will be greater than the time it takes to hand-roll the glue code.


If he's going to spend time on each function to analyse its prototype,
then maybe he could stay at the Tcl level with ffidl (since he said he
was rusty with C). Or could he ? I'm sincerely asking, having never
used ffidl myself. Thanks for any advice.

-Alex


Now you got me wondering, too.

http://elf.org/ffidl/
http://elf.org/pub/ffidl-0.6/Ffidl0.6.zip

Here's a few bits for that API I did last weekend, now done with ffidl just to see
how it works for me.

-- tiepie.tcl --
package require Ffidl
package provide tiepie

namespace eval ::tiepie {
set lib "c:/programming/tpscope/debug/hs3.dll"
}

# types used from tiepie.h
::ffidl::typedef byte uint8
::ffidl::typedef word uint16
::ffidl::typedef dword uint32
::ffidl::typedef integer long

proc ::tiepie::ResultERR {result nameVar infoVar} {
upvar $nameVar name $infoVar info
switch -- $result {
0 {
return 0
}
1 {
set name "E_NO_HARDWARE"
set info "Hardware is not connected"
}
2 {
set name "E_NOT_INITIALISED"
set info "Hardware is not initialized"
}
4 {
set name "E_NOT_SUPPORTED"
set info "Feature is not supported in your hardware"
}
8 {
set name "E_NO_GENERATOR"
set info "Hardware doesn't have an AWG"
}
16 {
set name "E_INVALID_CHANNEL"
set info "Invalid channel"
}
32 {
set name "E_INVALID_VALUE"
set info "Invalid input value"
}
default {
puts "oops"
}
}
return 1
}

# word InitInstrument (word address);
#
::ffidl::callout ::tiepie::_InitInstrument {word} word [::ffidl::symbol
$::tiepie::lib InitInstrument] stdcall

proc ::tiepie::InitInstrument {{address 0}} {
set rtn [_InitInstrument $address]
if {[ResultERR $rtn name info]} {
return -code error -errorinfo $info -errorcode [list TIEPIE $name $info]
}
return
}

# word ExitInstrument (void);
#
::ffidl::callout ::tiepie::_ExitInstrument {void} word [::ffidl::symbol
$::tiepie::lib ExitInstrument] stdcall

proc ::tiepie::ExitInstrument {} {
set rtn [_ExitInstrument]
if {[ResultERR $rtn name info]} {
return -code error -errorinfo $info -errorcode [list TIEPIE $name $info]
}
return
}

# word GetSerialNumber (dword *serial);
#
::ffidl::callout ::tiepie::_GetSerialNumber {pointer-var} word [::ffidl::symbol
$::tiepie::lib GetSerialNumber] stdcall

proc ::tiepie::GetSerialNumber {} {
set serial [binary format [::ffidl::info format word] 0]
set rtn [_GetSerialNumber serial]
if {[ResultERR $rtn name info]} {
return -code error -errorinfo $info -errorcode [list TIEPIE $name $info]
}
binary scan $serial [::ffidl::info format word] endptr
return $serial
}

-- END tiepie.tcl --

It took a bit of work deciphering the documentation, but I think that looks right.
I'm a bit worried about the _GetSerialNumber callout as the function writes the
value to the pointer owned by the integer Tcl_Obj. Is this valid? Doesn't look
valid to me. Not a big deal with pointers to numbers, but strings would make a
mess of things.

Does it work, though? NOPE! I can't get the callout to GetSerialNumber to not
cause Tcl to crash.

Well, In the time it took me to start using ffidl and get this far, I could have
written about 20 fully working on the first try hand-rolled Tcl_ObjCmdProc
functions in C.

ffidl is not for me.

--
If you care, you just get disappointed all the time. If you don't care
nothing matters so you are never upset. -- Calvin

Attachment: signature.asc
Description: OpenPGP digital signature