Like that, it works on Linux, it works too on Windows if my tcl code calls
directly my compiled C code inside a dll. But it does not work if my dll is
included in a kit (though the 1st solution with sprintf is OK, except when my
Message is too long of course).
I use tclkit and tclkitsh 8.5.9 on Windows XP and my compiler is gcc (TDM 4.5.2
version on Windows).
I have tried others solutions like :
Tcl_SetVar(interp,"v1_out",Message,TCL_GLOBAL_ONLY);
or :
Tcl_Obj * ResultObj ;
ResultObj = Tcl_NewStringObj(Message,-1);
Tcl_SetObjResult(interp,ResultObj);
It's always OK when my tcl code calls directly the dll, but never work when It's
inside a kit. I obtain this error :
Microsoft Visual C++ Runtime Library
Runtime Error !
This application has requested the Runtime to terminate it in an unusual way, ...
Apparently, I have not such problems under Linux and tclkit (though versions are
a little bit different).
So, what is wrong ?
Thanks for your help.
Gerard
Hi Gerard,
I think the 200 characters limit is due to sprintf.
The crash is weired, anyway. At least, the Obj method looks very clean
to me. When the sprintf helps, there must be something with variable scope.
- Did you try to put "Message" (and the data it points to) in a global
variable (just for test) ?
- TCL_Stubs enabled ?
I have MS-VC++ Express installed. If something crashes, I have the
possibility to start the C development environment and trace back on the
stack to find the errorneous calling procedure.
If error happens also, if your DLL is not wrapped but you load it from a
tclkit, you may use MSVC++ Express to set a breakpoint in the dll and
use step-by step processing to eventually find the reason for the issue.
J'éspère que ca aide un peu,
Harald
Don't do that. Its been deprecated for about 12 years or more.
Tcl_SetObjResult(interp, Tcl_NewStringObj(Message, -1));
should be the way to do this. This should take a copy of the string
and allocate it into a new Tcl object. I'd suspect the other failures
are due to memory for the string being allocated by one heap while the
Tcl copy used another heap.
Make sure that your extension DLL is compiled with TCL_STUBS and
linked to tclstub8[456].lib. Tclkit cannot work with non-stubs linked
extensions.
>
> On 12 April 2011 15:18, Gerard Durand <gerard-florence.durand <at> orange.fr>
wrote:
> > Hi,
> > I'm trying to return a long chain from C to Tcl.
> > If I use :
> > sprintf(interp->result,"%s",Message) ; with Message containing my character
>
> Don't do that. Its been deprecated for about 12 years or more.
>
OK, but I have still many codes doing that ...
>
> Tcl_SetObjResult(interp, Tcl_NewStringObj(Message, -1));
> should be the way to do this. This should take a copy of the string
> and allocate it into a new Tcl object. I'd suspect the other failures
> are due to memory for the string being allocated by one heap while the
> Tcl copy used another heap.
>
> Make sure that your extension DLL is compiled with TCL_STUBS and
> linked to tclstub8[456].lib. Tclkit cannot work with non-stubs linked
> extensions.
>
That was the reason apparently. Now I have compiled and linked with TCL and TK
stubs and it works on a small test. Normally, it should also work on a bigger
code (I hope :-))
Thanks for the help.
Gerard
Well, stop doing that. Really. It was deprecated in 1998.
--
73 de ke9tv/2, Kevin