Re: C++/TCL Need Solution to Compile Error c2784
- From: David Gravereaux <davygrvy@xxxxxxxxx>
- Date: Mon, 16 Apr 2007 20:45:16 -0700
I unfortunately have way too much to comment on. So here's my post again (that
google didn't pick up) of my stab at those two.
Let's hand roll those two. I'll assume the return code is an error code, with
zero being success and *handle is set by the function on return. The commands in
the interp will be [jnior::Connect <ip> <port> <user> <pass>], it returns the
handle of the connection. [jnior::Disconnect <handle>] will do the disconnect
called with the handle returned from Connect.
command to compile would be something like this:
cl -nologo -MD -IC:\tcl\include jnior_tcl.c -link -dll -out:jniortcl.dll
-libpath:C:\Tcl\lib jnior300.lib
--- jnior_tcl.c -----
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <limits.h>
#include "jnior_300.h"
#define USE_TCL_STUBS
#include "tcl.h"
/* Mark this .obj as needing Tcl's Stubs library. */
#pragma comment(lib, "tclstub" \
STRINGIFY(JOIN(TCL_MAJOR_VERSION,TCL_MINOR_VERSION)) ".lib")
/* Protos */
__declspec(dllexport) Tcl_AppInitProc Jniortcl_Init;
Tcl_ObjCmdProc ConnectCmd;
Tcl_ObjCmdProc DisconnectCmd;
/* Optional, but explicit. */
BOOL WINAPI
DllMain (HINSTANCE hInst, ULONG ulReason, LPVOID lpReserved)
{
if (ulReason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(hInst);
return TRUE;
}
int
Jniortcl_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(jnior::,name)), \
JOIN(name,Cmd), 0L, 0L);
MAKECMD(Connect);
MAKECMD(Disconnect);
Tcl_PkgProvide(interp, "jnior", "0.1");
return TCL_OK;
}
int
ConnectCmd (ClientData clientData, Tcl_Interp *interp,
int objc, struct Tcl_Obj * CONST * objv)
{
long ok, handle;
char *ip, *username, *password;
unsigned short port;
int iPort;
if (objc != 5) {
Tcl_WrongNumArgs(interp, 1, objv, "ip port user pass");
return TCL_ERROR;
}
ip = Tcl_GetString(objv[1]);
if (Tcl_GetIntFromObj(interp, objv[2], &iPort) != TCL_OK) {
return TCL_ERROR;
}
if (iPort < 0 || iPort > USHRT_MAX) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("port out-of-range",-1));
return TCL_ERROR;
}
port = (unsigned short) iPort;
user_name = Tcl_GetString(objv[3]);
password = Tcl_GetString(objv[4]);
ok = Connect(ip, port, &handle, user_name, password);
if (ok == 0) {
Tcl_SetObjResult(interp, Tcl_NewLongObj(handle));
return TCL_OK;
} else {
/* handle error condition here */
return TCL_ERROR;
}
}
int
DisconnectCmd (ClientData clientData, Tcl_Interp *interp,
int objc, struct Tcl_Obj * CONST * objv)
{
long ok, handle;
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "handle");
return TCL_ERROR;
}
if (Tcl_GetLongFromObj(interp, objv[1], &handle) != TCL_OK) {
return TCL_ERROR;
}
ok = Disconnect(handle);
if (ok == 0) {
/* success */
return TCL_OK;
}
return TCL_ERROR;
}
--
How many boards would the Mongols hoard if the Mongol hordes got bored?
-- Calvin
Attachment:
signature.asc
Description: OpenPGP digital signature
- Follow-Ups:
- Re: C++/TCL Need Solution to Compile Error c2784
- From: JesusChuyCampos
- Re: C++/TCL Need Solution to Compile Error c2784
- References:
- C++/TCL Need Solution to Compile Error c2784
- From: JesusChuyCampos
- Re: C++/TCL Need Solution to Compile Error c2784
- From: David Gravereaux
- Re: C++/TCL Need Solution to Compile Error c2784
- From: JesusChuyCampos
- Re: C++/TCL Need Solution to Compile Error c2784
- From: Christian Gollwitzer
- Re: C++/TCL Need Solution to Compile Error c2784
- From: David Gravereaux
- Re: C++/TCL Need Solution to Compile Error c2784
- From: Alexandre Ferrieux
- Re: C++/TCL Need Solution to Compile Error c2784
- From: David Gravereaux
- Re: C++/TCL Need Solution to Compile Error c2784
- From: David Gravereaux
- Re: C++/TCL Need Solution to Compile Error c2784
- From: JesusChuyCampos
- Re: C++/TCL Need Solution to Compile Error c2784
- From: David Gravereaux
- Re: C++/TCL Need Solution to Compile Error c2784
- From: JesusChuyCampos
- C++/TCL Need Solution to Compile Error c2784
- Prev by Date: Re: Tcl/Tk 8.5
- Next by Date: tclhttpd: Deleting files fails after broken upload
- Previous by thread: Re: C++/TCL Need Solution to Compile Error c2784
- Next by thread: Re: C++/TCL Need Solution to Compile Error c2784
- Index(es):
Relevant Pages
|