Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Making DLLs for DBPRO

Author
Message
Rims Flames
11
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 3rd Sep 2014 23:25
Hey guyz,

Any tutorials for making DLLs for DBPRO? I would really appreciate.
As a second question, can i make want dll i want with any functions to affect the input, graphics etc?

Thank You!

Rims Flames
SamKM
15
Years of Service
User Offline
Joined: 25th May 2009
Location:
Posted: 3rd Sep 2014 23:54
Most DBPro DLLs are put together in C++, as far as I know
Someone made a template ages back which might help you get started:
http://forum.thegamecreators.com/?m=forum_view&t=97069&b=5
With DLL plugins, you can add new commands, but not change existing ones as far as I know, if that's what you mean by affect the input - sorry about that :/
Good luck

The code never bothered me anyway...
Rims Flames
11
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 4th Sep 2014 00:38
Oh...i don't know how to import the template given to that link and there is no actual tutorial on how to do this and that step by step or i am missing something?

Rims Flames
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 4th Sep 2014 04:54
IanM wrote something on this a while ago. I did some digging and found this thread:
http://forum.thegamecreators.com/?m=forum_view&t=191280&b=18

You'll also want to check his website, he claims there's more material and a framework there.
http://www.matrix1.demon.co.uk/

Writing DLLs for DBP is the same as writing DLLs for any other program. The standard procedure is to pull in DBP's include files and link against the necessary DBP DLLs.

There's also a defined startup procedure you need to follow. When DBP loads your DLL it'll try to pass in a pointer to its global struct, which you can use to manipulate basically everything inside DBP.

UNIX is simple and coherent, but it takes a true genius to understand and appreciate its simplicity -- Dennis Ritchie
WickedX
16
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 4th Sep 2014 05:20
A good start would be the Third Party Commands in the Technical Documents section of the DarkBasic Professional help file.

Rims Flames
11
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 4th Sep 2014 15:17
The technical documents from DBPRO didn't helped me i did what Lee said but i couldn't compiled the DLL. TheComet, i will read what you sent me and i will give a feedback. Thank You all!

Rims Flames
Hotline
16
Years of Service
User Offline
Joined: 22nd Aug 2008
Location:
Posted: 4th Sep 2014 16:31
Quote: "The technical documents from DBPRO didn't helped me i did what Lee said but i couldn't compiled the DLL"


Can you show us the error message you get from Visual studio ? That might help

[href=forum.thegamecreators.com/?m=forum_view&t=191567&b=5]Spark Particle engine[/href]
[href=forum.thegamecreators.com/?m=forum_view&t=199163&b=5]Transform gizmo plugin[/href]
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 4th Sep 2014 20:52
Remember to mark the functions you wish to export with __declspec(dllexport). Also for these functions to be directly accessible to DBPro as a "command" you have to add string table entries that matches the DBPro function name to the name of your actually exported function. The exported function name may be mangled and you need to take this into account when writing your string table entries.
The string table entries need to use an id value between 101 and 999 or the DBPro compiler won't read it and are written using the following layout:
Quote: "DBPRO FUNCTION NAME WHICH MAY CONTAIN SPACES BUT NO OTHER SPECIAL CHARACTERS[%XYZ%exportedFunctionName"

The opening square bracket is optional; if it is present it indicates that the function will return a value. If it does then the first data type specifier in the XYZ list is the return type of the function. A function that doesn't return anything and doesn't have any arguments specify a single zero between the two % signs.
The XYZ part consists of one or more letters which indicate the data type of the argument in order (or as stated above, if a return value is provided by the function, that one's data type letter comes first).
There are a number of valid specifiers and some of them actually require a certain argument layout of your function, such as the ones taking an array pointer. However the standard, "normal" ones are as follows:
○ L - 32-bit signed integer
○ D - 32-bit unsigned integer; this is used for BYTE, WORD and DWORD alike which are all really 32-bit values (or castable from and to it) as far as DBPro is concerned
○ F - 32-bit floating point value. If returning a float, the actual C++ function should return the float's bit pattern interpreted as a DWORD.
○ S - Zero-terminated string. Proper DBPro string handling requires using the CreateDeleteString function that is pointed to by the Globstruct that you can receive a pointer to through the startup procedure TheComet hinted at. This function is called to let the DBP engine delete and/or allocate string memory; if you don't do this any previous DBPro strings won't be deleted and you'll thus end up with memory leaks.
○ R - 64-bit integer (double integer)
○ O - 64-bit floating point value (double float)


The startup / shutdown routine made available by DBPro is as follows:

void __cdecl Constructor(void) is called after your plugin has been loaded "for use".
You can use the DLLMain entry point for setup, but beware that this is in fact called twice when loading the plugin during compilation for validating the presence of function calls inside it. As such it is probably not desireable to do any hefty setup routine from there.

void __cdecl ReceiveCoreDataPtr(void *pCore) is called next and will give you the globstruct pointer as described above. Include the "Globstruct.h" header file from DarkSDK and cast the void pointer to sGlobstruct* and store it in a globally accessible pointer variable if you need it (chances are you will, if you for example need to return strings).

void __cdecl PreDestructor(void) is called during shutdown of your program.
I believe it is called before any of the dll's are actually unloaded so that you can do any cleanup operations that require access to other loaded dll's.

void __cdecl Destructor(void) is called prior to unloading your dll and can be used to contain cleanup logic (free dynamically allocated memory etc.).

If you don't need any of these callbacks you can just omit writing / exporting those functions, they're not mandatory.
Also, the PreDestructor / Destructor functions are NOT called if the DBPro program crashes, so I tend to use the DLLPROCESS_DETACH reason invocation of DLLMain to do the actual cleanup. This is called automatically by Windows and will be called even in the case of a crash. You cannot be sure in what order the dll's are unloaded though, so if you need guaranteed access to those the PreDestructor should be used, but with emergency cleanup done from DLLMain if found necessary. Of course modern OS'es (such as probably any Windows version DBPro programs will run on) will restore memory after a crash anyway so you might argue that this part is rather unnecessary.



Finally, as Hotline said, you should show us your compilation errors if those occur. Chances are there are linker errors due to missing (or no) libraries being included.


"Why do programmers get Halloween and Christmas mixed up?"
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 4th Sep 2014 23:34
Is there anyway to write the string table entries in VSexpress? Have not had much luck with this and the links are all dead to the external resource editor googling turned up

Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 5th Sep 2014 00:38 Edited at: 5th Sep 2014 00:39
I believe you can write resource (.rc) files yourself; they use a plain text statement-like format so it shouldn't be that hard once you get used to it. You then include this file along with your project and the compiler should be fine with it.
Then again I haven't been using VS Express for a long time so I'm not sure if it works in the latest versions or if there were more steps you needed to do.

Apart from some setup and defines, the format goes like this:


You can have several such STRINGTABLE BEGIN ... END blocks; I believe you can only have up to at most 16 entries each.


"Why do programmers get Halloween and Christmas mixed up?"
WickedX
16
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 5th Sep 2014 01:18
If you’re like me and learn better if you have source code to examine. This is a DLL I was working on. Since I don’t use DBPro much anymore, I release it here for anyone to do with what they may. The source was programmed using Visual C++ 2008. There are also 7 demo’s of some of its functions.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2025-05-15 21:03:31
Your offset time is: 2025-05-15 21:03:31