| View previous topic :: View next topic |
| Author |
Message |
dangt Newbie
Joined: 19 May 2009 Posts: 20
|
Posted: Tue May 19, 2009 4:49 pm Post subject: C++ dll |
|
|
| Is there any documents out there on writing VDS dlls in C++? |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Tue May 19, 2009 9:47 pm Post subject: |
|
|
I don't believe there are any examples for C++, but here is one for C.
It would probably be pretty easy to convert.
Make sure you turn off underscores for DLL exports in your compiler if you need to.
| Code: |
#include <windows.h>
typedef void __cdecl (* exteventproc)(char * eventtype);
#define MAX_PAR 11 // max parameters (including function or command)
#define BUF_LEN 256 // transfer buffer length (max total chars)
exteventproc eventproc; // address of event notification procedure
int errorcode = 0; // error code for FuncProc()
__declspec(dllexport) char * __cdecl Init(int Handle, exteventproc Addr, char * KeyString, int &maxpar, int &bufsize);
__declspec(dllexport) int __cdecl CommandProc(char * Params);
__declspec(dllexport) char * __cdecl FuncProc(char * Args);
__declspec(dllexport) int __cdecl StatProc(void);
// Globals //
char *input[MAX_PAR]; // array of pointers for input strings
int WINAPI LibMain(HINSTANCE hinst, unsigned long reason, LPVOID lpvReserved)
{
if(reason == DLL_PROCESS_ATTACH) // runs this code when DLL has loaded
{ //MessageBox(NULL, "DLL Loaded", "TEST.DLL", MB_OK);
}
if(reason == DLL_PROCESS_DETACH) // runs this when VDS program terminates
{ //MessageBox(NULL, "DLL Unloading", "TEST.DLL", MB_OK);
}
return 1;
}
ULONG GetNextArgPos(char * string, ULONG pos) // finds next null char
{ while(string[pos]!= '\0')
{ pos ++;
}
pos++; // start of next string, or end of params if still null
return pos;
}
void ParseInput(char * string) // calls "GetNextArgPos"
{ ULONG pos = 0;
int i = 0;
while(i < MAX_PAR)
{ input[i] = &string[pos];
if(string[pos] != '\0') // assign last null to unused pointers
pos = GetNextArgPos(string, pos);
i++;
}
}
char * __cdecl Init(int Handle, exteventproc Addr, char * KeyString, int &maxpar, int &bufsize)
{
eventproc = Addr;
maxpar = MAX_PAR;
bufsize = BUF_LEN;
return "COMMANDNAME"; // <---- Change to your DLL's command/function name
// Check for registration number here, DEMO in this case //
/*
if(lstrcmpi(KeyString,"DEMO") == 0)
{ //MessageBox(NULL, KeyString, "TEST.DLL - Keystring", MB_OK);
return "COMMANDNAME"; // Command and function name
}
else
{ return "";
}
*/
}
int __cdecl CommandProc(char * Params)
{
ParseInput(Params);
/*
if (strcmpi(input[0],"INIT") == 0)
{
// Initialize your DLL here if you need to
}
*/
return 0;
//eventproc(">>event test<<"); // <---- Set an @event() if you need to
//return 0;
}
// DLL Function commands here
char * __cdecl FuncProc(char * Args)
{
ParseInput(Args);
return "0";
}
int __cdecl StatProc(void)
{
return errorcode;
}
|
_________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Wed May 20, 2009 2:14 pm Post subject: |
|
|
The original example was written in Borland C++ however the code itself is C. I have written VDS DLL's in Dev-CPP, Watcom C++, Microsoft Visual C++... Pretty much any C/C++ compiler can be used to write VDS DLL's. I have posted examples and you should be able to use any of the C examples in a C/C++ compiler without too much issue. _________________ Home of
Give VDS a new purpose!
 |
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Wed May 20, 2009 2:26 pm Post subject: |
|
|
Below is a simpler function for walking the parameters and arguments passed to CommandProc and FuncProc.
| Code: |
char *parambuf;
char* NextParam(void)
{
// Wow this function works just
// like the Delphi version ;)
//
// Duplicate the current parameter at
// the current memory address of parambuf
char *nextparam = parambuf;
// Jump to the memory address of
// the next parameter
while(*parambuf != '\0') parambuf++;
// Set parambuf to the byte right after
// the null character of the next
// parameter
parambuf++;
// return the nextparam
return nextparam;
}
|
This function is similar to the Delphi versions I have seen. To use it just do this.
| Code: |
parambuf = Params; // assign the address of Params to global parambuf variable
char *currentparam; // pointer to the current parameter
currentparam = NextParam(); // call NextParam to get the next parameter from parambuf.
|
_________________ Home of
Give VDS a new purpose!
 |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|