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



JesusChuyCampos@xxxxxxxxx wrote:

Any help is greatly appreciated.

Hi Jesus,

I can't hold back.. I must say my real thoughts..

Automation sux!

Be it CPPTCL or even SWIG, your interfaces never turn-out the way you really want
it. Don't put me in a box, please. Forget the c++ template error thing for the
moment.

Last weekend I wrote an interface library for a PC-controlled USB oscilloscope.
It has a whooping 82 function calls and took me 2 days to get it 70% done. But
the work was well worth it as I can specify all parameters for exactly how I want
the interface to be.

You do need to know how Tcl works on the inside but the learning curve isn't all
that steep. Once you have an extension framework, adding more commands for the
externals isn't that hard, and more than likely all the functions are somewhat
orthogonal so you end-up reusing error checking and param decoding code.

Spend the time to learn Tcl's C API and hack away at your extension without
fighting those helper tools. Just ask questions here, if you get a bit stuck on
some concepts like Tcl_Obj reference counting, or whatever.


Here's an example of one of the calls from the scope library I turned into a Tcl
command..

word SetSensitivity(byte byCh, double *dSens); /* from scope control dll */

becomes:

Tcl_ObjCmdProc SetSensitivityCmd;

__declspec(dllexport) int
Tpscope_Init (Tcl_Interp *interp)
{
#ifdef USE_TCL_STUBS
if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
....
# define MAKECMD(name) \
Tcl_CreateObjCommand(interp, STRINGIFY(JOIN(tiepie::,name)), \
JOIN(name,Cmd), 0L, 0L);
....
MAKECMD(SetSensitivity);
....
}

int
SetSensitivityCmd (ClientData clientData, Tcl_Interp *interp,
int objc, struct Tcl_Obj * CONST * objv)
{
word ok;
byte ch;
double sensitivity;

if (objc != 3) {
Tcl_WrongNumArgs(interp, 1, objv, "channel sensitivity");
return TCL_ERROR;
}

if (GetChannelFromObj(interp, objv[1], &ch) != TCL_OK) {
return TCL_ERROR;
}

if (Tcl_GetDoubleFromObj(interp, objv[2], &sensitivity) != TCL_OK) {
return TCL_ERROR;
}

ok = SetSensitivity(ch, &sensitivity);
if (TiePieResultOK(interp, ok)) {
/* return actual */
Tcl_SetObjResult(interp, Tcl_NewDoubleObj(sensitivity));
return TCL_OK;
}
return TCL_ERROR;
}

byte
GetChannelFromObj(Tcl_Interp *interp, Tcl_Obj *obj, byte *ch)
{
int channel;

*ch = 0;
if (Tcl_GetIntFromObj(interp, obj, &channel) != TCL_OK) {
return TCL_ERROR;
}

if (channel < 0 || channel > 4) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("channel out-of-range",-1));
return TCL_ERROR;
}

*ch = (byte)channel;
return TCL_OK;
}

int
TiePieResultOK (Tcl_Interp *interp, word result)
{
const char *msg, *eName;

switch (result) {
case E_NO_ERRORS:
return 1;

case E_NO_HARDWARE:
eName = "E_NO_HARDWARE";
msg = "Hardware is not connected";
break;
case E_NOT_INITIALISED:
eName = "E_NOT_INITIALISED";
msg = "Hardware is not initialized";
break;
case E_NOT_SUPPORTED:
eName = "E_NOT_SUPPORTED";
msg = "Feature is not supported in your hardware";
break;
case E_NO_GENERATOR:
eName = "E_NO_GENERATOR";
msg = "Hardware doesn't have an AWG";
break;
case E_INVALID_CHANNEL:
eName = "E_INVALID_CHANNEL";
msg = "Invalid channel";
break;
case E_INVALID_VALUE:
eName = "E_INVALID_VALUE";
msg = "Invalid input value";
break;
case (E_LAST<<1):
eName = "E_NO_SUCH_API";
msg = "API not found in DLL";
break;
default:
eName = "????";
msg = "Unknown error";
break;
}

if (interp) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1));
Tcl_SetErrorCode(interp, "TIEPIE", eName, msg, NULL);
}
return 0;
}


--
A voice crackles in Calvin's radio:
"Enemy fighters at two o'clock!"
"Roger. What should I do until then?"

Attachment: signature.asc
Description: OpenPGP digital signature



Relevant Pages

  • RFC: if_clone overhaul
    ... Please test/review the following patch to the network interface cloneing ... static void ... -if_clone_lookup(const char *name, int *unitp) ... static int gifmodevent; ...
    (freebsd-net)
  • [PATCH 3/7] adding xc5000 tuner chip driver
    ... this code also uses the tunerchip.h interface which allows to attach ... It uses the latest Xceive reference driver which fixes some issues. ... new file mode 100644 ... unsigned int frequency; ...
    (Linux-Kernel)
  • [PATCH] usbmon: add binary interface
    ... USB records are stored in a liked list, alike current text interface implementation, so most code is shared from binary and text interface. ... unsigned int cmd, unsigned long arg) ... struct urb *urb, char ev_type) ...
    (Linux-Kernel)
  • Re: Possible to pass strings back to ASP from ActriveX?
    ... afx_msg int AboutBox; ... helpstring("AxTemplateTest1 ActiveX Control module"), ... // Primary dispatch interface for CAxTemplateTest1Ctrl ... helpstring("Dispatch interface for AxTemplateTest1 Control")] ...
    (microsoft.public.windowsce.embedded)
  • Re: identity...... Was: The wisdom of the object mentors
    ... // this is it's implementation/mapping from a hidden domain of {int x int} ... construction mechanism.....for this I need to show a construction! ... I'd say that the set of all propositions is language defined behavior or ... But what about implementation and the interface of a type? ...
    (comp.object)