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 / How do you call DBP commands from a C++ plugin?

Author
Message
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 5th Jun 2011 14:46
I'm trying to produce a plugin for DBPro using Visual C++ 2008 express edition, and I was wondering if someone could show me how to access commands from other DBPro plugins.

For example, I can write this in DBPro:

But how do I write a method in C++ so I can do:


I have managed to call DBP commands before now, but with a few flaws. If my entire DBP program is this command

where Mycommand calls Paste image, get image, etc. then it will fail as the Image library has not been loaded. I find that I must do this:

for it to work, as the first get image loads the image library and then my plugin commands can work. I'm fairly certain there will be a way round this, but I'm still rather new to making DLL's - any help would be appreciated!

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
D Ogre
20
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 6th Jun 2011 00:14
Have a look at this thread:
http://forum.thegamecreators.com/?m=forum_view&t=172906&b=18

IIRC, There are several other threads that give examples that show you how to use DBPro commands in your plugins.
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 14th Jun 2011 13:55
Thanks for the link, it's a thread I had seen before but I'm glad I looked at it again. This is what I've managed to come up with so far for loading the bitmap library:


I have a few queries though:
1) Does "Core->g_Bitmap" make DBPro automatically load the Bitmap Library?

2) I don't understand this line:

What's the difference between "GetBitmapPtr" and "GetBitmapPtr_t"? I appreciate they are pointers to the location of the "CreateBitmap" function within the DBP Dll, but how exactly do they work?

3) Last and most important, once I have GetBitmapPtr, how do I use this to execute "Create Bitmap"?
(At the moment, the method is blank and just returns an integer)


I'd be glad of any advice you could give (or example code!), I've been loooking round the forums for a while now and still haven't gotten hold of any really clear explanations about how you set up DLLS.

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Jun 2011 15:07
1. No. Read the code in the link again - there's an array named Dependencies and two functions called GetNumDependencies and GetDependencyID that do that.

2. GetBitmapPtr is a variable, and GetBitmapPtr_t is a type (specifically, a function pointer type).

3. Don't do that. Name your function pointers appropriately (i.e. call it CreateBitmap, not GetBitmapPtr). Once you have the pointer in the variable, just pretend it's a function - CreateBitmap(...args...).

Bottom line: If you don't understand function pointers, then learn about them first ... http://www.newty.de/fpt/index.html

Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 20th Jun 2011 17:25
Quote: "No. Read the code in the link again - there's an array named Dependencies and two functions called GetNumDependencies and GetDependencyID that do that."

Ah, yes, that was a pretty dumb mistake on my part, I thought there was a shortcut to loading the libraries using Core->g_Bitmap (I realised it didn't work just after I posted). Just out of curiosity, how do you access a DBPro main plugin without using LoadLibrary? I can't quite understand your comment in the exmaple:



Thanks for the link, it explained everything brilliantly - it was maddeningly simple once I figured it out, but I'd never have worked it out on my own. I have just one final query, connected with how I grant multiple .cpp files access to the DBP commands. Currently, I use the following for my project:

DarkGUI.h (header for main project file)


DarkGUI.cpp (Main source file)



Form.h (header for second file that uses DBP commands)


Form.cpp



The code compiles without any error and I'm fairly certain this is the correct method of sharing the function pointers, but I was just wondering if I was right in this approach, or is there a better way? Am I also correct in thinking that "void ReceiveCoreDataPtr(LPVOID CorePtr)" is called before any other DLL command can be accessed, so there is no possibility of the function pointers being null/undefined?

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Jun 2011 21:38 Edited at: 20th Jun 2011 21:38
Quote: "I can't quite understand your comment in the exmaple"

It meant that I could have used Core->g_Basic3D, but chose not to for the sake of the example. I used LoadLibrary in the example, because not all plug-ins have an entry in the GlobStruct structure (the DBProCore.dll is an example, plus other third-party plug-ins).

Quote: "but I was just wondering if I was right in this approach"

It's fine, except for the fact that you don't unload the bitmap library when you are done - I did that in the PreDestructor call in my example code and you should do the same if you stick with this approach. However, in this instance, it might be better for you to use Core->g_Bitmap instead of loading the library yourself.

Quote: "Am I also correct in thinking that "void ReceiveCoreDataPtr(LPVOID CorePtr)" is called before any other DLL command can be accessed, so there is no possibility of the function pointers being null/undefined?"

Yes.

Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 21st Jun 2011 14:34
That's brilliant, thanks for all your help!

We spend our lives chasing dreams. Dark Basic lets us catch some of them.

Login to post a reply

Server time is: 2024-03-28 19:49:02
Your offset time is: 2024-03-28 19:49:02