Tcl_Eval creates a error messagebox 
Author Message
 Tcl_Eval creates a error messagebox

--------------34EBC5AFDD278C0F7030B840
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Hello,

I try to write a windowsprogram, which uses a tcl interpreter for small
math. operations.

These are the steps in my program (Please check the example program at
the end of the text !):
1.  Create a interpreter with Tcl_CreateInterp(...).
2.  Setup a link between a C variable dA and a tcl variable a using
Tcl_LinkVar(...).
3.  Evaluation of a script with Tcl_Eval. The script writes the result
of the calculation to the tcl variable a and the c variable dA too.
4.  Delete interpreter with Tcl_DeleteInterp(...).

During the evaluation of the script set a [expr asin(1.1)] I
discovered a strange behavior of the tcl library:
A error messagebox is created twice:
        title of the window: name of the executable program
        message: asin: DOMAIN error
        icon: ERROR-symbol

Then Tcl_Eval returns TCL_ERROR. Something similar happens during the
usage of other math. functions with parameters out of there valid range.
For other errors in tcl-scripts Tcl_Eval silently returns only
TCL_ERROR.

My questions are:
-Is there something I have made wrong ?
-Is this a bug or a feature ?
-Is there a way to suppress the creation of the error messagebox from C
?

Im using TCL 8.0, Windows NT 4.0, MS Visual C++ 5.0.

Any suggestions are welcome!

Thanks for reading my message !


Heres the program:

#include <windows.h>
#include "tcl.h"

//Start program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
 LPSTR lpCmdLine, int nCmdShow)
{
     //Token for the interpreter structure
     Tcl_Interp* pTclInterp=NULL;

     //testscript 'set a[expr asin(1.1)]'
     char cTclScript[]="set a [expr asin(1.1)]\n";

     //Outputvariable for scriptoperations
     double dA=NULL;

     //Returnvalue of Tcl_Eval
     int iReturnValue=NULL;

     //Buffer for string output
     char cReport[200]="";

     //Create a new interpreter
     pTclInterp=Tcl_CreateInterp();
     if(pTclInterp==NULL)
     {
          MessageBox(0,"Can't create a tcl interpreter !",
              "ERROR",MB_OK|MB_ICONERROR);
          return(1);
     };

     //Setup a link between the c variable 'dA' and the tcl variable 'a'

     iReturnValue=Tcl_LinkVar(pTclInterp,"a",(char*) &dA,
TCL_LINK_DOUBLE);
     if(iReturnValue!=TCL_OK)
     {
          MessageBox(0,"Unable to link c-variable 'dA' to tcl
interpreter !",
               "ERROR",MB_OK|MB_ICONERROR);
          Tcl_DeleteInterp(pTclInterp);
          return(1);
     };

     //Evaluate current script
     iReturnValue=Tcl_Eval(pTclInterp,cTclScript);

     //Check if script evaluation was successful
     if(iReturnValue!=TCL_OK)
     { //ERROR
          MessageBox(0,"Error during evaluation of script !",
               "ERROR",MB_OK|MB_ICONWARNING);
     }
     else
     { //Success
          sprintf(cReport,"Result of script: %f", dA);
          MessageBox(0,cReport,"Script evaluation successful !",
               MB_OK|MB_ICONINFORMATION);
     };

     //Remove link between the c variable 'dA' and the tcl variable 'a'
     Tcl_UnlinkVar(pTclInterp,"a");

     //Delete interpreter
     Tcl_DeleteInterp(pTclInterp);

     //Back to Windows
     return(0);

Quote:
};

--------------34EBC5AFDD278C0F7030B840
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

<HTML>
<FONT SIZE=-1>Hello,</FONT>

<P><FONT SIZE=-1>I try to write a windowsprogram, which uses a tcl interpreter
for small math. operations.</FONT>

<P><FONT SIZE=-1>These are the steps in my program (Please check the example
program at the end of the text !):</FONT>
<BR><FONT SIZE=-1>1.&nbsp; Create a interpreter with Tcl_CreateInterp(...).</FONT>
<BR><FONT SIZE=-1>2.&nbsp; Setup a link between a C variable dA and a
tcl variable a using Tcl_LinkVar(...).</FONT>
<BR><FONT SIZE=-1>3.&nbsp; Evaluation of a script with Tcl_Eval. The script
writes the result of the calculation to the tcl variable a and the c
variable dA too.</FONT>
<BR><FONT SIZE=-1>4.&nbsp; Delete interpreter with Tcl_DeleteInterp(...).</FONT>

<P><FONT SIZE=-1>During the evaluation of the script set a [expr asin(1.1)]
I discovered a strange behavior of the tcl library:</FONT>
<BR><FONT SIZE=-1>A error messagebox is created twice:</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; title of the
window: name of the executable program</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message: asin:
DOMAIN error</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; icon: ERROR-symbol</FONT>

<P><FONT SIZE=-1>Then Tcl_Eval returns TCL_ERROR. Something similar happens
during the usage of other math. functions with parameters out of there
valid range. For other errors in tcl-scripts Tcl_Eval silently returns
only TCL_ERROR.</FONT>

<P><FONT SIZE=-1>My questions are:</FONT>
<BR><FONT SIZE=-1>-Is there something I have made wrong ?</FONT>
<BR><FONT SIZE=-1>-Is this a bug or a feature ?</FONT>
<BR><FONT SIZE=-1>-Is there a way to suppress the creation of the error
messagebox from C ?</FONT>

<P><FONT SIZE=-1>Im using TCL 8.0, Windows NT 4.0, MS Visual C++ 5.0.</FONT>

<P><FONT SIZE=-1>Any suggestions are welcome!</FONT>

<P><FONT SIZE=-1>Thanks for reading my message !</FONT>
<BR>&nbsp;


<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P><FONT SIZE=-1>Heres the program:</FONT>

<P><FONT SIZE=-1>#include &lt;windows.h></FONT>
<BR><FONT SIZE=-1>#include "tcl.h"</FONT>

<P><FONT SIZE=-1>//Start program</FONT>
<BR><FONT SIZE=-1>int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,</FONT>
<BR><FONT SIZE=-1>&nbsp;LPSTR lpCmdLine, int nCmdShow)</FONT>
<BR><FONT SIZE=-1>{</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; //Token for the interpreter
structure</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; Tcl_Interp* pTclInterp=NULL;</FONT>
<BR><FONT SIZE=-1>&nbsp;</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; //testscript 'set a[expr asin(1.1)]'</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; char cTclScript[]="set a [expr
asin(1.1)]\n";</FONT>

<P><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; //Outputvariable for scriptoperations</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; double dA=NULL;</FONT>

<P><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; //Returnvalue of Tcl_Eval</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; int iReturnValue=NULL;</FONT>

<P><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; //Buffer for string output</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; char cReport[200]="";</FONT>

<P><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; //Create a new interpreter</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; pTclInterp=Tcl_CreateInterp();</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; if(pTclInterp==NULL)</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; {</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
MessageBox(0,"Can't create a tcl interpreter !",</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"ERROR",MB_OK|MB_ICONERROR);</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return(1);</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; };</FONT>

<P><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; //Setup a link between the c
variable 'dA' and the tcl variable 'a'</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; iReturnValue=Tcl_LinkVar(pTclInterp,"a",(char*)
&amp;dA, TCL_LINK_DOUBLE);</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; if(iReturnValue!=TCL_OK)</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; {</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
MessageBox(0,"Unable to link c-variable 'dA' to tcl interpreter !",</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"ERROR",MB_OK|MB_ICONERROR);</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Tcl_DeleteInterp(pTclInterp);</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return(1);</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; };</FONT>

<P><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; //Evaluate current script</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; iReturnValue=Tcl_Eval(pTclInterp,cTclScript);</FONT>
<BR><FONT SIZE=-1>&nbsp;</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; //Check if script evaluation
was successful</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; if(iReturnValue!=TCL_OK)</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; { //ERROR</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
MessageBox(0,"Error during evaluation of script !",</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"ERROR",MB_OK|MB_ICONWARNING);</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; }</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; else</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; { //Success</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
sprintf(cReport,"Result of script: %f", dA);</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
MessageBox(0,cReport,"Script evaluation successful !",</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
MB_OK|MB_ICONINFORMATION);</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; };</FONT>

<P><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; //Remove link between the c variable
'dA' and the tcl variable 'a'</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; Tcl_UnlinkVar(pTclInterp,"a");</FONT>

<P><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; //Delete interpreter</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; Tcl_DeleteInterp(pTclInterp);</FONT>

<P><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; //Back to Windows</FONT>
<BR><FONT SIZE=-1>&nbsp;&nbsp;&nbsp;&nbsp; return(0);</FONT>
<BR><FONT SIZE=-1>};</FONT>
<BR>&nbsp;</HTML>

--------------34EBC5AFDD278C0F7030B840--



Mon, 20 Mar 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Error BASE/2012 Create error: AC01.DBF (DOS Error 32)

2. How to hide the error display from Tcl_Eval?

3. Compile error tclX7.3a-p2 (Tcl_Eval)

4. DOS Error 3, TERM/2014 Create error: LPT2.PRN

5. orexx.exe error -- error log is being created

6. MessageBox doesnt stay open in deployed image

7. Deployed app terminates after a MessageBox is displayed before main app shell view is opened

8. How to put an MessageBox...

9. VSE - MessageBox - help button

10. VAST: Stopped processes during display of Messageboxes

11. ]VSE} MessageBox is a Process Hog

12. Messagebox xp memory block freed twice??

 

 
Powered by phpBB® Forum Software