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 / Help starting writing DLLs

Author
Message
Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 27th Nov 2003 16:18
I know there are quite a few experienced DLL coders in these forums, so I would really appreciate it if you could help me to start integrating my basic (and I mean basic) C knowledge into DBPro. I just don't really know where to start, so maybe if you know some example code for a function that outputs the factor of two numbers, like...

print multiply(2,3)

Just something basic like that (I hope it's basic ). I can write a function like that in C easily but just not integrate it into dbpro. Maybe if I can get a simple example then I can work from there. Thanks a lot.

Do you bite your thumb at me sir?

Athelon XP 1600 Plus - Nvidia Geforce MX400 - 256mb RAM
CattleRustler
Retired Moderator
22
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 27th Nov 2003 17:41
I think your dll would need to be written in C++ or PureBASIC for it to work in dbp - not 100% sure though

-RUST-
waffle
23
Years of Service
User Offline
Joined: 9th Sep 2002
Location: Western USA
Posted: 27th Nov 2003 18:05
its been too long for me to do a DLL in C++.
In PB the code looks the same as DB excepts for......

A DLL in C++ or in PB is the same as any other windows app (using the same compilier) except for the extra initialization procedures and the (_EXTERN macro in C++ / procedureDLL macro in PB) They get even easier to write if you use a windows object DLL, but then you might not be able to use it in DB. If your C++ is rusty, why bother with doing a DLL? You'll spend alot of time just trying to do a "Hello World" message box function when you could be working on the next best game in the world today If there was some special task you wanted or needed, Just ask in the forum and I'm sure, if its a good idea, someone will make one for you.

Oh, i forgot to mention CDEL. This determines the order in which variables are pushed/popped from the stack to use them as parameters in your DLL functions. And then there is the C++ name mangling to deal with too.

Just remember, if you ask for a DLL to perform a task, please show how it would be used and why DB can't do that task already without a DLL. Simply saying DB polygon collision is too slow and you want a faster way just won't get you anywhere.

internet gaming group
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Nov 2003 19:34
All of the above, plus you can really use any language that you want - as long as it fits what's been said already

C is more than capable enough to do this
Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 27th Nov 2003 19:34
I dont need any specific dll, and I'm not trying to write a dll for dbpro, I just want to learn how to, and I was asking how to form the code so it can be used as a dll.

Do you bite your thumb at me sir?

Athelon XP 1600 Plus - Nvidia Geforce MX400 - 256mb RAM
The Game
23
Years of Service
User Offline
Joined: 22nd Dec 2002
Location: United States
Posted: 27th Nov 2003 19:43
IanM's website has probably what you are looking for. Look for Framework - A Basic TPC DLL framework

http://www.matrix1.demon.co.uk/DBPro/TPCDLLS-downloads.html

I am the game and I want to play.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Nov 2003 19:47 Edited at: 27th Nov 2003 19:51
[edit]It's mostly aimed at C++, which is why I haven't mentioned it - some stuff is a lot different.

Also, the Constructor/ReceiveCoreDataPtr/Destructor won't get called for C unless you do some fancy footwork with your .DEF file[/edit]

Here's your multiply function as an example - depending on the compiler that you using you'll need to modify this to ensure that the function is exported.

The obscure stuff in the return statement is needed, as it's how DBPro passes floats around

Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 27th Nov 2003 19:59
Thanks for that, the float info was helpful, but my compiler (borland 5.5) claims there is a syntax error on the first line.

So that should just compile on its own into a dll? Or is that just the function?

Do you bite your thumb at me sir?

Athelon XP 1600 Plus - Nvidia Geforce MX400 - 256mb RAM
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Nov 2003 20:12 Edited at: 27th Nov 2003 20:13
Include the windows.h header file at it should compile completely.

Just add 'declspec(dllexport)' at the start of the function line, at it'll work for you

Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 27th Nov 2003 22:34
Comes up with the error messages:

Multiply is not a parameter in function declspec

and

, expected in function declspec

I don't know if its the compiler or what, I'm using -WD command line to compile as a dll exe.

Do you bite your thumb at me sir?

Athelon XP 1600 Plus - Nvidia Geforce MX400 - 256mb RAM
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Nov 2003 00:12
Oops, 'declspec' should be '__declspec'
Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 28th Nov 2003 21:17
Thanks, I have it compiled into a .dll file succesfully now. However, I am not sure how to use the call dll() function. It says something about a dll export table in the help files. Could you show how to call the Multiply function from dbpro (man, I feel like a noob asking all these questions, guess I am really with dlls.). Thanks for your time.

Do you bite your thumb at me sir?

Athelon XP 1600 Plus - Nvidia Geforce MX400 - 256mb RAM
waffle
23
Years of Service
User Offline
Joined: 9th Sep 2002
Location: Western USA
Posted: 28th Nov 2003 21:35
"No. Sir. I do not bite my thumb at you, but I do bite my thumb"

Maybe start with a "Teach yourself C++ in 21 Days" book.
On the plus side, DLL programming is easier than windows, no message loops, unless you want them.

internet gaming group
Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 28th Nov 2003 21:40
Thanks, I am considering buying a book, although I have read through The C Programming Language, by Brian Kernighan and Dennis Ritchie (I know its not C++). I'm basically trying to link my DBPro coding to C as I learn it, to give myself a reason to learn it. I still need to know how to use call dll().

Do you bite your thumb at me sir?

Athelon XP 1600 Plus - Nvidia Geforce MX400 - 256mb RAM
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 28th Nov 2003 21:44
With CALL DLL, its quite simple :

Use CALL DLL with the DLL number, function name and then any parameters...


Mirrors are more fun than television. Well, that was fun, in a not-so-fun sort of way...
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Nov 2003 23:05
You'll need to find out the name of the function in your DLL yourself, because I don't know what name mangling system that Borland C++ uses.

Just follow the instructions in the TPC document in your help folder and that should help you find it.

Then just use something like this

Login to post a reply

Server time is: 2026-07-27 01:33:00
Your offset time is: 2026-07-27 01:33:00