forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ dll

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
dangt
Newbie


Joined: 19 May 2009
Posts: 20

PostPosted: Tue May 19, 2009 4:49 pm    Post subject: C++ dll Reply with quote

Is there any documents out there on writing VDS dlls in C++?
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Tue May 19, 2009 9:47 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Wed May 20, 2009 2:14 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Wed May 20, 2009 2:26 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
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

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group