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 / Decorated names in DLL's

Author
Message
YarSnez
23
Years of Service
User Offline
Joined: 9th Apr 2003
Location:
Posted: 12th Apr 2003 22:02
Hi, I've just discovered a little matter with DLL's and DB Pro with patch 4. I have Power Basic which can produce standard Win32 DLL's but does not decorate the functions names as per MS VC++. If I use the LOAD DLL, and CALL DLL methods in DB Pro, I can call a Power Basic's DLL functions no problem. However, if I then copy the DLL into the plugins-user directory, DB Pro does not see the added commands. It appears that the only way to add commands in this way is with decorated names using VC++. This had me busy for quite a while, and maybe useful for others who might try developing a DLL in another language such as Delphi, Power Basic etc. :-s
The One Ring
23
Years of Service
User Offline
Joined: 15th Sep 2002
Location: United States
Posted: 12th Apr 2003 22:04
I think the problem may be that you must add a string table resource to your DLL, which contains a specificly formatted list of functions. This is so DBPro knows how to read the commands in your plug-in.

Good, bad... I'm the guy with the gun. - Ash in Army Of Darkness(1993).
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 12th Apr 2003 22:08
you can't use DLLs produced without the resource setup like that... you must use the load dll [dllname],[position] then call the function like return=call dll([dllnumber],[function],[parameters])

however i've noticed if you produce DLLs from other basics... suchas PureBasic when you try to call them they'll crash DB/DBpro

you have to make your DLLs in a Pascal or C based language with pure functions no COM setup - this is why you also can't use Visual Basic apartently

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
YarSnez
23
Years of Service
User Offline
Joined: 9th Apr 2003
Location:
Posted: 12th Apr 2003 22:14
Thanks for the reply but I do have this in place. Isn't the string table also required when using the CALL DLL method? This I can do okay. Also, the patch 4 is supposed to remove the need for decorated names.

The One Ring
23
Years of Service
User Offline
Joined: 15th Sep 2002
Location: United States
Posted: 12th Apr 2003 22:17
It is true that you do not have to have decorated names. I add extern "C" to my function declarations in C++ to avoid mangled naming.

As far as if CALL DLL needs decorated naming, I'm not sure.

Good, bad... I'm the guy with the gun. - Ash in Army Of Darkness(1993).
YarSnez
23
Years of Service
User Offline
Joined: 9th Apr 2003
Location:
Posted: 12th Apr 2003 22:23
Out of interest I tried the demo DLL code on the DB CD. The TESTCOMMANDS example. This code uses the extern "C". After compiling this, I copied the DLL into the user-libs dir and alas, the functions were not found. However, when I removed the extern "C" line, and recompiled, it worked. So, just a little confused.

Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 12th Apr 2003 22:56
@YarSnez, the function name in the string table is not required for use by CALL DLL. The entry in the string table is only required for TPC Plugins.

The string table acts a bit like a translation table, listing the actual DLL command (eg PrintText), the command which the user types in DBP (eg: PRINT TEXT) and the paramters (message)

Current Project: Retro Compo. Entry.
YarSnez
23
Years of Service
User Offline
Joined: 9th Apr 2003
Location:
Posted: 12th Apr 2003 23:09
Thanks for the info. I had started to think this was the case.

Can you explain why the example code on the CD does not work unless I remove the extern "C" line. This suggests to me that decorated names are required despite the Patch 4 statement about decorated names not being required. Hmmm.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Apr 2003 01:21
In both types of DLL, you are able to use either decorated or undecorated names as you choose, however it is up to you to tell DBPro the name.

extern "C" removes the C++ name decoration and instead uses the C name decoration - some compilers add a leading underscore so be careful.

For example:
void MyFunc(void) is decorated as ?MyFunc@@YAXXZ is VC++

I can either set up a resource string that matches this *exactly* and use it as a TPC DLL, or I can call it using CALL DLL(1,"?MyFunc@@YAXXZ").

If you can tell me which example you are referring to, I can explain why you have a problem getting the code to work without changing it.
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 13th Apr 2003 01:36
hmm... i thought it was just my version of DarkBasic Pro that couldn't run the extern "C" commands.
i've got a little experimenting to see what actually does work though, because i must admit the functions i've been trying just don't like to work full stop right now lol

try a simple DLL like this
C/C++ ->


mycomm.h


setup the string table like so ->
true[%D%ReturnTrue%Boolean = true() ... i think that should work, i mean i'll test it in a sec but i'm fairly sure it should - unless the undecorated don't require the string table.

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
YarSnez
23
Years of Service
User Offline
Joined: 9th Apr 2003
Location:
Posted: 13th Apr 2003 12:33
Thanks very much for all the help and suggestions!

The example I was trying on the DB Pro CD was TESTCOMMANDS2 found under the help\documents\files\Third Party Commands dir.

However, I did remove some of the functions as I don't have DX8 SDK installed and therefore missing some of the include files. But commenting out all the string related functions I was able to compile the DLL with and without the extern "C" command found in the TESTCOMMANDS.H header. I found that with this option enabled the functions were not found by DB Pro. I guess I need to double check how my VC++ version is decorating the names.

I will also try Raven's code snippet to see what happends. Thanks again!
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 13th Apr 2003 17:58
Yes, if you want your DLL to act as a plug-in, the functions have to be decorated (even if you set up the string table). Ie, you cant use extern "C".

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
n3t3r453r
23
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Russia
Posted: 13th Apr 2003 18:48
Again DLLs ? May be someone will right a tutorial?

I'd like to change the world, but God doesn't want to give me sources!
YarSnez
23
Years of Service
User Offline
Joined: 9th Apr 2003
Location:
Posted: 13th Apr 2003 19:31
Thank you MrTAToad! That does confirm what I have found. It's a pity that this is the case as it means addons have to be written in C++, unless another language supports the same decorated name format.
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 13th Apr 2003 19:46
Now this is where is gets confusing - C++ (when compiled as a plug-in), will only run once (I haven't tried this for a while, so it may have changed). I cant remember what happens with the second go, but it didn't work at any rate (I dont seem to have the E-Mail I sent to Lee about it anymore unfortunately). I get around this by getting C to call any C++ classes.

C++ when used as a normal DLL will work any number of times.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
YarSnez
23
Years of Service
User Offline
Joined: 9th Apr 2003
Location:
Posted: 13th Apr 2003 19:59
I have just knocked up a little DLL with an exported function "Return100" which does just that. With the function name decorated, this works every time. Perhaps the problem with plug-ins not working the second time has gone? Hope so.
The One Ring
23
Years of Service
User Offline
Joined: 15th Sep 2002
Location: United States
Posted: 15th Apr 2003 03:03
MrTATodad said: "Yes, if you want your DLL to act as a plug-in, the functions have to be decorated (even if you set up the string table). Ie, you cant use extern "C"."

Actually, I have successfully compiled a DLL using extern "C" and called it as a plug-in from DBPro, Patch 4.

Good, bad... I'm the guy with the gun. - Ash in Army Of Darkness(1993).
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Apr 2003 11:20
The One Ping - I must admit I haven't tried undecorated names for a while, when doing plug-ins - the last time I tried, the second call would always crash. They may have fixed it now...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
YarSnez
23
Years of Service
User Offline
Joined: 9th Apr 2003
Location:
Posted: 15th Apr 2003 15:04
Gosh! Sometimes it works and sometimes it doesn't. Hmmmm! A case of plug-in and play, or not as the case maybe. Thanks for the feedback.

Login to post a reply

Server time is: 2026-07-10 19:47:52
Your offset time is: 2026-07-10 19:47:52