Re: How to load a DLL built by MS VC++ in tcl file?



If you know the name of the variable you want to receive, you can use Tcl_GetVar and friends: (this assumes a global variable z)

char *value;
value = Tcl_GetVar(interp, "z", TCL_GLOBAL_ONLY);

Tcl_Obj *value;
int intValue;
value = Tcl_GetVar2Ex(interp, "z", NULL, TCL_GLOBAL_ONLY);
if (value) {
Tcl_IncrRefCount(value);
if (Tcl_GetIntFromObj(interp, value, &intValue) != TCL_OK) {
// handle error...
}
Tcl_DecrRefCount(value);
// do what ever you want with intValue...
}

George

O/H fangvv έγραψε:
Thank you very much!

I still have a question. In my C++ program, I will invoke the tcl to
calculate some value for me. However, how can I get the value in C++
space after I got it in tcl. that is:

1. C++: TCL_EvalFile(demo.tcl)
2. Tcl: In demo.tcl:

load calculate.dll

if { getdata(x) == y } {
set z 12345
} else {
set z 54321
}

3. After the tcl calculation, My C++ program need to know the value of
z. So How can I get it in C++?

Thanks a lot!



On 2月22日, 下午10时14分, George Petasis <peta...@xxxxxxxxxxxxxxxxx> wrote:
O/H fangvv έγραψε:



I want to implemente a program. In this program, there is a tcl file
and a dll file. The dll file is generated by the MS Visual C++. It
uses a function getdata(x) to get the relative data for x. Then I can
load the dll to calculate and do some thing, such as
if { getdata(x) == y } {
puts "...."
} else {
puts "..."
}
I know there is a command called "load", however, the c example file
given in the man page is different from the common dll file in MS
Visual C++
http://www.tcl.tk/man/tcl8.5/TclCmd/load.htm
It does not have the common DllMain function. So I don't know how to
compile it in the MS Visual C++ environment to make it as a dll.
can someone help me ,plz? thanks a lot!
The load tcl command can load only dlls that are tcl extensions, i.e.
have a special function in them such as <package_name>_Init(Tcl_Interp
*). There are two alternatives for your dll:

1) If you have the source code, and you can compile it, you can convert
it to a tcl extension. See for examplehttp://wiki.tcl.tk/605,http://wiki.tcl.tk/1208,http://wiki.tcl.tk/2419
Swig fromwww.swig.orgcan be also handy, as it can create the needed C
code for you.

2) If you don't want to change the dll (or you don't have the source
code), you can try ffidl (http://wiki.tcl.tk/1197) or dll
(http://wiki.tcl.tk/12264).

George

.



Relevant Pages