Re: Problem with Tcl_SetResult and Tclkit under Windows

Harald Oehlmann <[email protected]> Tue, 12 Apr 2011 17:16:52 +0200
Newsgroups gmane.comp.lang.tcl.starkit
Message-ID <[email protected]>
Am 12.04.2011 16:18, schrieb Gerard Durand:
> 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 charact=
er
> chain, it works. But Message can not be more than 200 characters long
> (TCL_RESULT_SIZE limit).
> Normally the solution is to use Tcl_SetResult (and it will be the only on=
e with
> tcl 8.6 I think ! even for short strings) :
> Tcl_SetResult(interp,Message,TCL_VOLATILE);
>=20
> Like that, it works on Linux, it works too on Windows if my tcl code call=
s
> 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 whe=
n 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 =3D Tcl_NewStringObj(Message,-1);
>     Tcl_SetObjResult(interp,ResultObj);
>=20
> It's always OK when my tcl code calls directly the dll, but never work wh=
en 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, ...
>=20
> Apparently, I have not such problems under Linux and tclkit (though versi=
ons are
> a little bit different).

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'=E9sp=E8re que ca aide un peu,
Harald

--=20
You received this message because you are subscribed to the "starkit" group=
.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to starkit-unsubscribe@googlegro=
ups.com
For more options, visit this group at http://groups.google.com/group/starki=
t?hl=3Den