View previous topic :: View next topic |
Author |
Message |
Estas Contributor
Joined: 31 Jan 2004 Posts: 66 Location: Germany
|
Posted: Fri Feb 02, 2007 3:18 pm Post subject: Creating compatible VDS DLLs |
|
|
Hi all,
This is for advanced VDS developers:
I have written a DLL and I would like to adapt my source code so it conforms to VDS dll standards. Is there a link or a description on how to create VDS compatible DLLs? Or can someone who already developed VDS DLLs provide additonal instructions on how to do this?
The DLL I created works fine within VDS using the loadlib and @lib commands , see example below.
Greetings Mike
Download:
http://www.vdsworld.com/search.php?view_mode=fileinfo&file_id=485&sid=ab72cf3bca1c1a83847ae37c2d4a8805 _________________ Greetings to all the folks back home in the States. A friendly "hola -como estas" to all my friends from Spain and Greece.
Last edited by Estas on Sun Feb 04, 2007 12:20 am; edited 1 time in total |
|
Back to top |
|
|
Aslan Valued Contributor
Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
|
Back to top |
|
|
Estas Contributor
Joined: 31 Jan 2004 Posts: 66 Location: Germany
|
Posted: Fri Feb 02, 2007 3:49 pm Post subject: |
|
|
Thanks for the link - but I already checked on this one.
I am really having a hard time understanding this.
Is there something a bit less demanding available?
Mike _________________ Greetings to all the folks back home in the States. A friendly "hola -como estas" to all my friends from Spain and Greece. |
|
Back to top |
|
|
vdsalchemist Admin Team
Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Fri Feb 02, 2007 3:50 pm Post subject: |
|
|
Estas,
What language did you write your DLL with? _________________ Home of
Give VDS a new purpose!
|
|
Back to top |
|
|
Estas Contributor
Joined: 31 Jan 2004 Posts: 66 Location: Germany
|
Posted: Fri Feb 02, 2007 3:52 pm Post subject: |
|
|
I developed the DLL with "PureBasic".
The name of the DLL: GetTime.dll
The function name: GetTime
It takes one string parameter (the name of a ntp-time server)
It returns a string value which contains the current time _________________ Greetings to all the folks back home in the States. A friendly "hola -como estas" to all my friends from Spain and Greece. |
|
Back to top |
|
|
vdsalchemist Admin Team
Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Fri Feb 02, 2007 4:07 pm Post subject: |
|
|
Estas,
The code below has never been completely tested. I built this for Garrett a long time ago to see if it was possible but I don't own a copy of PureBasic and was never able to compile it.
Code: |
;
; ------------------------------------------------------------
;
; PureBasic - DLL example file Updated for use as a VDS DLL
;
; (c) 2002 - Fantaisie Software
; (c) 2006 - DragonSphere Software
;
; ------------------------------------------------------------
;
; This example is a skeleton to build easely a VDSDLL using PureBasic
; The dll is created in the 'Compilers' directory, under the
; 'purebasic.dll' name. An associated '.lib' is generated to use
; with LccWin32 or VisualC++.
;
; ------------------------------------------------------------------------------------------
; This example is far from a production VDSDLL but hopes it will help
; others to learn to build VDSDLL's in PureBasic.
; I don't know enough of the syntax of PB to write a fully working VDSDLL
; so I hope this will work.
; ------------------------------------------------------------------------------------------
; Things that will prob. not work right.
; 1) The event procedure since I don't know how to declare callback procedures in PB.
; 2) The NextParam procedure since I don't fully know how PB handles pointers to byte arrays.
; to build a NextParam procedure you would need a way to walk through a byte array
; one byte at a time skiping null chars (i.e. character 0) to get to the next Param
; and Args in the CommandProc and FuncProc procedures.
; ------------------------------------------------------------------------------------------
;
; Rules to follow:
; - Never write code outside a procedure, except for variables
; or structure declaration.
;
; - DirectX Init routines must not be initialized in the the
; AttachProcess() procedure
;
; - There is 4 procedures automatically called: AttachProcess(),
; DetachProcess(), AttachThread() and DetachThread(). If you don't
; need them, just remove them.
;
; This procedure is called once, when the program loads the library
; for the first time. All init stuffs can be done here (but not DirectX init)
;
Global errorcode.l
Declare eventproc(event.s)
;Global eventprocaddr.l
ProcedureDLL AttachProcess(Instance)
EndProcedure
; Called when the program release (free) the DLL
;
ProcedureDLL DetachProcess(Instance)
EndProcedure
; Both are called when a thread in a program call or release (free) the DLL
;
ProcedureDLL AttachThread(Instance)
EndProcedure
ProcedureDLL DetachThread(Instance)
EndProcedure
; Real code start here..
ProcedureCDLL Init.s(Handle.l, *Addr.l, KeyString$, *maxpar.l, *bufsize.l)
; First function VDS will call to initialize the DLL
; ie... External vdsdll.dll,KeyString
maxpar = 25 ; maxpar is a pointer to maximum number of parameters that the DLL can handle
bufsize = 256 ; bufsize if the size of the parameter string buffer
eventproc = Addr.l ; Should be the address of the event procedure in the VDS *.exe
Result$ = "VDSDLL" ; The name of the command and function should be returned to VDS
;KeyString is the string that the External command passes as the second parameter
;of the Init procedure.
errorcode = 0 ; Initialize errorcde to zero
ProcedureReturn Result$
EndProcedure
ProcedureCDLL CommandProc.l(Params$)
; VDS calls this procedure when a command is executed
; VDS requires a long to be returned.
; Params$ is a list of arguments delimited by the null character
; VDS Fucntion Example:
; VDSDLL Hello,World
; Params$ will look like the following byte array
; Hello0World0
; Basicly Params$ is multiple strings combined into a single byte array buffer
; the zero's are null characters
Ret.l = 0
ProcedureReturn Ret
EndProcedure
ProcedureCDLL FuncProc.s(Args$)
; VDS calls this procedure when a function is called from the DLL.
; VDS requires a string to be returned from functions
; Args$ is a list of arguments delimited by the null character
; VDS Fucntion Example:
; %A = @VDSDLL(Hello,World)
; Args$ will look like the following byte array
; Hello0World0
; Basicly Args$ is multiple strings combined into a single byte array buffer
; the zero's are null characters
strRet$ = "1"
errorcode = -1 ; Set @OK() to false
ProcedureReturn strRet$
EndProcedure
ProcedureCDLL StatProc.l()
; VDS will call this procedure from time to time to see
; if the FuncProc procedure has an errorcode to set.
; This procedure does not take any paramters
ProcedureReturn errorcode
EndProcedure
; IDE Options = PureBasic v3.94 (Windows - x86) (Demo)
; ExecutableFormat = Shared Dll
; CursorPosition = 9
; Folding = --
; Executable = C:\Programmation\Projets\PureBasic Visual Designer\Dll.Exe
|
_________________ Home of
Give VDS a new purpose!
|
|
Back to top |
|
|
Estas Contributor
Joined: 31 Jan 2004 Posts: 66 Location: Germany
|
Posted: Fri Feb 02, 2007 4:13 pm Post subject: |
|
|
WOW - this is pretty cool and probably exactly what I was looking for!!!
Thanks - I am going to take a closer look at it right away...
I'll let you know if it got me any further...
Mike _________________ Greetings to all the folks back home in the States. A friendly "hola -como estas" to all my friends from Spain and Greece. |
|
Back to top |
|
|
vdsalchemist Admin Team
Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Fri Feb 02, 2007 8:00 pm Post subject: |
|
|
Mike,
I had another version of that source code that included the NextParam procedure. I think it is on my PC at home. I will look for it and if I find it I will post that here _________________ Home of
Give VDS a new purpose!
|
|
Back to top |
|
|
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sat Feb 03, 2007 12:12 am Post subject: |
|
|
Definitely let us know the results, as I never got around to trying out the
code in PureBasic yet myself.
Thanks,
-Garrett _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
Back to top |
|
|
Estas Contributor
Joined: 31 Jan 2004 Posts: 66 Location: Germany
|
Posted: Sat Feb 03, 2007 6:39 am Post subject: |
|
|
Well, I think I got it to work...
exept for one thing: I can't retrieve the parameter which in this case contains the stringname of the time-server.
In VDS I call the function this way:
%%Time = @GetTime("utcnist.colorado.edu")
The functions is initialized correctly and executed but without the name of the parameter.
How do I pass on this string so that the procedure can process the name of the timeserver? _________________ Greetings to all the folks back home in the States. A friendly "hola -como estas" to all my friends from Spain and Greece. |
|
Back to top |
|
|
Estas Contributor
Joined: 31 Jan 2004 Posts: 66 Location: Germany
|
Posted: Sat Feb 03, 2007 7:24 am Post subject: |
|
|
Ok - I solved the problem with the parameter...
But now I get an error message from VDS:
"Error in external command or function"
I'll try to find out what causes that error and keep you updated.
Mike _________________ Greetings to all the folks back home in the States. A friendly "hola -como estas" to all my friends from Spain and Greece. |
|
Back to top |
|
|
vdsalchemist Admin Team
Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Sat Feb 03, 2007 2:46 pm Post subject: |
|
|
Mike,
VDS throws these errors when your DLL does not capture or deal with system errors. Also VDS is very picky about the string it gets back. If it cannot read or understand the pointer that is being returned by the FuncProc procedure then it will throw an error. I was torn as to rather the return variable strRet$ needed to be global or not??? I know in C and C++ you cannot return a character array directly. You have to return a pointer to the character array. _________________ Home of
Give VDS a new purpose!
|
|
Back to top |
|
|
Estas Contributor
Joined: 31 Jan 2004 Posts: 66 Location: Germany
|
Posted: Sat Feb 03, 2007 5:45 pm Post subject: |
|
|
I got it done - at last it works.
Well, I defined the return string "strRet$" as NOT Global.
The error I received was due to a small assembler routine within my procedure, which VDS seemingly didn't like and therefor returned an error message.
DragonSphere/Garret: The PureBasic roster for creating VDS-Dlls is working. I had to rewrite a few lines though because the source provided is for version 3.94 and I am currently using 4.02.
Thanks to both of you.
I will upload the final dll to the ExtensionSection so it can be downloaded and tested by other VDS users who might need a timeserver function in their program. _________________ Greetings to all the folks back home in the States. A friendly "hola -como estas" to all my friends from Spain and Greece. |
|
Back to top |
|
|
GeoTrail Valued Contributor
Joined: 18 Feb 2003 Posts: 572 Location: Bergen, Norway
|
Posted: Sat Feb 03, 2007 6:08 pm Post subject: |
|
|
Minor update of dragonsphere code for PB 4.02 compatibility Code: | ;
; ------------------------------------------------------------
;
; PureBasic - DLL example file Updated for use as a VDS DLL
;
; (c) 2002 - Fantaisie Software
; (c) 2006 - DragonSphere Software
;
; ------------------------------------------------------------
;
; This example is a skeleton to build easely a VDSDLL using PureBasic
; The dll is created in the 'Compilers' directory, under the
; 'purebasic.dll' name. An associated '.lib' is generated to use
; with LccWin32 or VisualC++.
;
; Updated to work with PureBasic 4.02. - GeoTrail
;
; ------------------------------------------------------------------------------------------
; This example is far from a production VDSDLL but hopes it will help
; others to learn to build VDSDLL's in PureBasic.
; I don't know enough of the syntax of PB to write a fully working VDSDLL
; so I hope this will work.
; ------------------------------------------------------------------------------------------
; Things that will prob. not work right.
; 1) The event procedure since I don't know how to declare callback procedures in PB.
; 2) The NextParam procedure since I don't fully know how PB handles pointers to byte arrays.
; to build a NextParam procedure you would need a way to walk through a byte array
; one byte at a time skiping null chars (i.e. character 0) to get to the next Param
; and Args in the CommandProc and FuncProc procedures.
; ------------------------------------------------------------------------------------------
;
; Rules to follow:
; - Never write code outside a procedure, except for variables
; or structure declaration.
;
; - DirectX Init routines must not be initialized in the the
; AttachProcess() procedure
;
; - There is 4 procedures automatically called: AttachProcess(),
; DetachProcess(), AttachThread() and DetachThread(). If you don't
; need them, just remove them.
;
; This procedure is called once, when the program loads the library
; for the first time. All init stuffs can be done here (but not DirectX init)
;
Global errorcode.l
Declare eventproc(event.s)
;Global eventprocaddr.l
ProcedureDLL AttachProcess(Instance)
EndProcedure
; Called when the program release (free) the DLL
;
ProcedureDLL DetachProcess(Instance)
EndProcedure
; Both are called when a thread in a program call or release (free) the DLL
;
ProcedureDLL AttachThread(Instance)
EndProcedure
ProcedureDLL DetachThread(Instance)
EndProcedure
; Real code start here..
ProcedureCDLL.s Init(Handle.l, *Addr.l, KeyString$, *maxpar.l, *bufsize.l)
; First function VDS will call to initialize the DLL
; ie... External vdsdll.dll,KeyString
maxpar = 25 ; maxpar is a pointer to maximum number of parameters that the DLL can handle
bufsize = 256 ; bufsize if the size of the parameter string buffer
eventproc = Addr.l ; Should be the address of the event procedure in the VDS *.exe
Result$ = "VDSDLL" ; The name of the command and function should be returned to VDS
;KeyString is the string that the External command passes as the second parameter
;of the Init procedure.
errorcode = 0 ; Initialize errorcde to zero
ProcedureReturn Result$
EndProcedure
ProcedureCDLL.l CommandProc(Params$)
; VDS calls this procedure when a command is executed
; VDS requires a long to be returned.
; Params$ is a list of arguments delimited by the null character
; VDS Fucntion Example:
; VDSDLL Hello,World
; Params$ will look like the following byte array
; Hello0World0
; Basicly Params$ is multiple strings combined into a single byte array buffer
; the zero's are null characters
Ret.l = 0
ProcedureReturn Ret
EndProcedure
ProcedureCDLL.s FuncProc(Args$)
; VDS calls this procedure when a function is called from the DLL.
; VDS requires a string to be returned from functions
; Args$ is a list of arguments delimited by the null character
; VDS Fucntion Example:
; %A = @VDSDLL(Hello,World)
; Args$ will look like the following byte array
; Hello0World0
; Basicly Args$ is multiple strings combined into a single byte array buffer
; the zero's are null characters
strRet$ = "1"
errorcode = -1 ; Set @OK() to false
ProcedureReturn strRet$
EndProcedure
ProcedureCDLL.l StatProc()
; VDS will call this procedure from time to time to see
; if the FuncProc procedure has an errorcode to set.
; This procedure does not take any paramters
ProcedureReturn errorcode
EndProcedure
|
_________________
Last edited by GeoTrail on Sat Feb 03, 2007 8:44 pm; edited 1 time in total |
|
Back to top |
|
|
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sat Feb 03, 2007 6:56 pm Post subject: |
|
|
Dragonsphere, Estas and GeoTrail, thanks for all the help and info on this
-Garrett _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
Back to top |
|
|
|