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 / Getting 3rd Party DLL Handles From The GlobStruct - Is It Possible?

Author
Message
D Ogre
20
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 10th Feb 2010 03:38
If I write a plugin and want to use a 3rd party plugin as a dependency,
where do I get the DLL handle from?

Does DBPro use the g_spare slots in the GlobStruct, or are those DLL
handle slots in the GlobStruct reserved specifically for future DBPro DLLs?

What would be the proper procedure in getting those 3rd party DLL handles?
LoadLibrary? Other?
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Feb 2010 14:16
Quote: "where do I get the DLL handle from?"

You don't - you get it from LoadLibrary right now.

I say 'right now' because DBPro must keep a list of handles for loaded DLLs so that it can release the library when it shuts down - I think I know where they are kept but not for sure yet.

Mistrel
Retired Moderator
18
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 10th Feb 2010 18:50
You can use GetModuleHandle to get the handle of a library that's already open.

Just don't use FreeLibrary on it.

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Feb 2010 19:23
True, but that provides the opportunity for the DLL to be unloaded before you've finished with it. If you use LoadLibrary, there is no such problem (provided that no-one uses FreeLibrary without having used LoadLibrary).

D Ogre
20
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 11th Feb 2010 01:38
I thought so. I couldn't see any other way to do this myself.

@IanM

If you can figure out a way to get access to that DLL handle list, could you
please post some information on it. I would be very interested in this.


Thanks for the input guys.
Mistrel
Retired Moderator
18
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 13th Feb 2010 06:36 Edited at: 13th Feb 2010 06:36
That's true, IanM. But if someone is unloading DBP DLLs before the program has ended then you've got bigger problems elsewhere.

If this is the case then GetModuleHandle means one less handle to forget to close.

Or to accidentally free.

Whichever perspective you prefer.

D Ogre
20
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 14th Feb 2010 21:27 Edited at: 14th Feb 2010 21:34
I believe you both have some valid points.

I guess it really depends on how the 3rd party plugins are written. If we are talking about
plugins that use external libraries (non-DBPro) and memory, they should by all rights free
those resources before exiting themselves. That's something that should have been done by the
original 3rd party plugin and not the plugin written that uses it as a dependency. I thought
we used the PreDestructor and Destructor functions for this purpose? Just as long as those
functions are not being used to free something that is used by another plugin before exiting.

This brings me to some other questions. Shouldn't all the resources used in a terminated DBPro
program be freed by all the respective DLLs included with the project excutable? Whatever the
case is, how does it determine the teardown order?
Mistrel
Retired Moderator
18
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 15th Feb 2010 00:52
I think it all comes down to preference.

Quote: "Shouldn't all the resources used in a terminated DBPro
program be freed by all the respective DLLs included with the project excutable? Whatever the case is, how does it determine the teardown order?"


There is some decorated destructor that DBP can call but I don't know what it is. DLLMain should signal ProcessDetach though once all handles have been freed.

Yes, it's the responsibility of each plugin author to handle memory allocation and deallocation. For example, I've experienced memory corruption when accidentally loading the newton physics DLL multiple times with LoadLibrary. Sometimes it's just not handled correctly.

Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 20th Feb 2010 16:45
You can add these functions to your dll



Those will be called by dbpro(Constructor and RecieveCoreDataPtr at start and Destructor at end)

New Site! Check it out \/
D Ogre
20
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 20th Feb 2010 17:20
@ Caleb1994

Yes, I am aware of those functions. Don't for get there is also a Predestructor too. That's not exactly what I was asking about. I was talking about how DBPro determines the order of making those calls and how it attaches and detaches process upon initialisation and teardown of itself internally.

Login to post a reply

Server time is: 2024-04-26 11:52:29
Your offset time is: 2024-04-26 11:52:29