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.

DLL Talk / Creating a DLL that calls DBP functions... Are there any easier ways?

Author
Message
WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 10th Oct 2011 01:41
I'm at the point where I'm defining the functions from each dll but it seems somewhat of a very tedious task. I'm using "DLL Export Viewer" to view the decorated and undecorated names from the DBP dll's and I believe it will also export something called a .def file, whatever that is used for.

I've got the standards of the dll ready made and I'm just building on it:

This stuff is for DBP to call some various functions when the dll is loaded: (I don't know whether the "Destructor()" should actually be used to unload libraries)


The main include for any functions I write:


And here's one of the cpp files that populates the DBP_Bitmap functions:


I've done it so that if a library hasn't already been loaded by DBP then it will flag it and load it and on exit it will check the flag and unload the library if needed.

Is there an actual simpler way to populate the function pointers than having to write out tons of "GetProcAddress()"'s?

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 10th Oct 2011 13:45
@WLGfx
You could write a program to automatically generate a .h and .cpp file from the DBPro DLLs which automatically does all that. Alternatively you could use preprocessor macros to speed it up a bit, but you'd still have to manually find all the decorated function names. If you search these forums there was a plugin sdk made by Aaron Miller which imported all the functions (he used the first option above) but it may require a bit of tweaking to get it to work with the latest versions of DBPro/MSVC++.

[b]
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Oct 2011 15:10
... or I could send you a copy of my own Interface Library, as Arron's library was slightly incorrect in the first place and is now something like 5 years out of date.

Just let me know what version of C++ (2003, 2008 or 2010) you are using and I'll prepare it for you.

Quote: "I don't know whether the "Destructor()" should actually be used to unload libraries"

There's almost no good reason to use the Destructor in your plug-ins. Any 'final' processing involving other plug-ins should be carried out in the PreDestructor 'void PreDestructor(void);'. In the PreDestructor, the other plug-ins are guaranteed to still be loaded in memory, while in the Destructor there is a chance that they have already been unloaded.

WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 10th Oct 2011 15:19
@Diggsey - I might just do that, generate .h and .cpp files, and comment out the blocks of functions I don't actually need. The pre-processor macros will be a better option too. It just seemed so long winded as I was looking through the dll with the DLL viewer. I'll also check out Aaron Millers utility (I think I've already seen it but not sure).

The idea is basically implement a load of C++ stuff that I've collected and add the functionality to DBPro while my mind can't get focused on a single part of the game I eventually want to write. And I don't want to make mega huge plugins that only one call would be used so I'll seperate the functionality of each section (like IanM has done) so that not all will be linked to the final exe produced by DBPro.

And I'd also like to finish off with a tutorial and a skeleton for any other plugin writers out there now that I've got this far.

Thanks Diggsey...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 10th Oct 2011 15:21 Edited at: 10th Oct 2011 15:22
Ah, that I wasn't sure about. I'm using MSVC++ 2008 Express IanM..

Any help is always appreciated. I'm getting a little more confident with this C++ stuff like I was years ago with C and asm...

@IanM - Thank you... That would help a lot...

EDIT: I did read that unloading libraries just decrements a counter or something until it finally gets flushed out of the system...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Oct 2011 16:28
It does, but if you use the GetNumDependencies/GetDependencyID system to get DBPro to include plug-ins at compile time and to load them at runtime, along with GetModuleHandle, then you never really increment the reference count in the first place.

The only time I use LoadLibrary with my own plug-ins is for those libraries that are entirely optional, or within my Interface Library where it isn't known whether the other plug-in will be loaded automatically or not.

WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 10th Oct 2011 17:14
Although I've gone about it the right way by checking whether the dll has been loaded already, I didn't really need that because the Dependencies already sets that up. Oh... I did wonder why that was there.

If I was allocating memory at run time, then the necessary de-allocating and general clean up should go in which, Pre / Destructor?

The setting up and closing down of a DLL isn't an issue at all with speed, it's just getting it right. All that will come into play when I turn my attention to throwing the actual usable functions.

As with the converting the decorated dll list, I may create one file and just copy over the necessary ones for that particular plugin as I need them.

The one thing I will need to ask is I noticed in the Basic3D dll there is a "Make Object New", maybe similar to one from your own plugins. It is something I am going to need for a number of things but I don't want to have to check each time a DBP coder has your plugins installed. I'm not yet familiar with DX but the DBP engine should be more than fine for me to manually create objects from my own plugin. I hope...

As a side note, if you want to attach anything I do to your plugin library then your more than free to do so. One plugin set fits all. It would be so much easier for a DBP user to do than installing multiple plugins. The Perlin Noise for example. And any others, such as procedural texture generation that I'm working on as I know now that they are only attached to the final exe if they are used. I'd even prefer to just download one thing that does lots of stuff.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 10th Oct 2011 19:52
I would have mentioned your one too Ian, but I thought you were still keeping it secret

[b]
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Oct 2011 20:33
Nah, it's no secret. I keep thinking about re-releasing it publicly and properly, but then I remember the support hassles I used to get.

That's kind-of decided now though I guess

@WLGfx,
Quote: "If I was allocating memory at run time, then the necessary de-allocating and general clean up should go in which, Pre / Destructor?"

That's your call - If I already have a PreDestructor, then I throw the code in there, in the same way as if I have a ReceiveCoreDataPtr, I put startup code there instead of the Constructor.

Quote: "there is a "Make Object New""

I guess you're talking about the CreateNewObject functions that are available.

If you take a look at the header files I've provided, then you'll see that they are divided up by DLL (ie, DBProBasic3DDebug.dll functions are available from Basic3D.hpp).

All the functions that are straight conversions from the available commands are listed first in alphabetical order. All additional functions that I've picked out as 'useful' are then listed later in no particular order - CreateNewObject is one of these, but it's not quite as easy to use as you may think. I think I can find a simple example from some old code of mine if you need it.

Anyhow, check out the header files, add the include and lib directories to your compiler, and then just use it - every function provided is in the DBPro namespace, so if you have predictive keying on, typing 'DBPro::' will pop up a list of everything. All of the DBPro command names were converted using the simple system of capitalising the first letter of each word, and then removing the spaces, so MAKE OBJECT CUBE becomes DBPro::MakeObjectCube(...), and RGB becomes DBPro::Rgb(...) etc.

Anyhow, I also forgot to ask whether you needed the code to be compiled as multithreaded, or multithreaded DLL (which needs the runtime DLLs), so I've done both.

The one attached to this post is the multithreaded DLL version.

Attachments

Login to view attachments
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Oct 2011 20:38
... and here's the plain multithreaded version.

Attachments

Login to view attachments
WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 10th Oct 2011 21:49 Edited at: 10th Oct 2011 22:05
Thank you again IanM, I've got some reading through to do now. That as well as DX surfaces, and probably more.

CreateNewObject() doesn't give too much away in any of the code sources (dll, google source, etc) so I'm assuming it's then creating an sObject* and passing that to DBP. If you have got something I could use or look at for that purpose that would be more than helpful.

One of the purposes for this is for generating fauna, etc for terrain. Grass, plants, trees and very likely alien plant life and have them instanced across sections of terrain. I've been playing around with this theme for some time and instead of converting the code into DBP code I may as well implement this particular one as a very simple plugin. (maybe I'll write some better help files this time round too)

Addition to said "adding PNoise to your Matrix1 library": Although I haven't made a fantastic help file for the PNoise dll, the source has already been released for it. I actually think that once something is set solid then they should be packed up as one whole plugin set for download, especially those that provide plugins free.

EDIT: I've just noticed there's this function:
CreateMeshForObject(int ObjectNumber,DWORD FvfFormat,DWORD VertexCount,DWORD IndexCount);
... but as I'm using a browser I can't find any more information about what this does yet. Darn... Where did that SVN thingy go...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Oct 2011 22:39
Create a 'blank' object - 1 mesh, fully zeroised that you then fill in yourself using the vertexdata commands:


... named CREATE BLANK OBJECT so it doesn't clash with any of DBPro's or my commands.

WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 11th Oct 2011 13:49 Edited at: 11th Oct 2011 13:50
@IanM - That is so much easier. It does save a hell of a lot of trouble setting up the dll function imports.

I'm using the 'multi-threaded-dll' for working on the plugins code, testing the initial code using the pgdk libs. Getting somewhere.

Mega thanks for saving probably weeks of hassle.

(I'll have some useful stuff for DBP users sooner than I thought)

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 14th Oct 2011 05:34 Edited at: 14th Oct 2011 15:34
I'm having a little problem with this: It's just returning a single character from the fileselector...



Altered the code slightly to what the destructions say to do but setting it up I'm lost to get it working in DBP.

EDIT: String table addition is...


EDIT2: I've just tried this too:


But still only returns the first letter. I'm having problems converting a WCHAR to CHAR...

FIXED: Change the properties to use "multibyte" instead of unicode...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Oct 2011 15:51 Edited at: 14th Oct 2011 15:52
You might find it easier to use the DBPro::CreateString and DBPro:[/b]b]DeleteString helper functions to play with your strings.

Also, apart from when returning a float, I always return the proper type (despite the fact that Lee does otherwise) - I've never had a problem with that, and it's far easier to code:


WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 14th Oct 2011 16:20
Wow! That is so much less hassle. I did see them functions but wasn't aware that they were helper functions to do that. Thank you again... Something I'll remember.

I think the biggest headache last night was not having "multibyte" coding on.

I've also thrown the LoadLibrary("win32.dll"); and FreeLibrary(); into the DLL Attach and DLL detach...

Looks like I'll be writing DBP extras for some time now...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Oct 2011 23:21
Quote: "I've also thrown the LoadLibrary("win32.dll"); and FreeLibrary(); into the DLL Attach and DLL detach..."

Never do that.

Best practices for creating DLLs

Basically, there are so many drawbacks to using DllMain that it's easier to not include one and to use DBPro's standard startup functions - that's what they are there for after all.

WLGfx
11
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 16th Oct 2011 01:13
I've had a read through that and afterwards looked into a few more references too. Cheers.

I've removed the "win32.dll" completely and it still works without the need to load the library. I think in future I'll check whether a required library is already loaded.

So different from programming the Amiga...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2019-10-18 21:48:56
Your offset time is: 2019-10-18 21:48:56