Use dll with LoadLibrary () method in C ++
Let me suggest some things left in the question:
- You have a dynamic link library called flubber.dll
- The library exports the function
bool GetFlubber(Flubber* flubber)
. - The function and type
Flubber
(which just isstruct
!) Are both declared in the flubber.h header file .
If these 3 conditions are met, you can use LoadLibrary
in flubber.dll , and then GetProcAddress
with GetFlubber
as named proc, and finally, you can declare Flubber
local and pass it GetFlubber
through the received address proc.
source to share
Hmm ... I'm afraid this question was a little difficult to understand.
In C ++, a struct declaration is just a declaration. It doesn't generate what you can load at runtime, it is pure compilation that just tells the compiler how things are laid out in memory, fields, their types and order, etc.
source to share
I am assuming you are using VC ++ 2005.
MS now provides you with Delay Loading Dll .
Visual C ++ component now supports DLL load delay. This saves you the hassle of using the Windows SDK's LoadLibrary and GetProcAddress functions to implement lazy DLL loading.
Steps to follow to configure download delay.
Go to Project-> Properties-> Linker-> Input and then list your Dll in "DLL Delay Delays"
source to share
Like the other answers, it's hard to tell what is being asked here, but I'll answer a different interpretation of the question. I'm not sure if it's "officially supported", but you can export a DLL to a global variable and then dynamically access it via GetProcAddress.
For example, if a library named foo.dll contains a global type FOO named g_MyGlobal, then it can export the variable to foo.def. The client code can then call:
MyPointer = GetProcAddress(..., "g_MyGlobal");
and get the "FOO *" pointer to the global.
... but with that said, if you need to do this for anything other than private testing, you might want to consider your design. It would probably be much safer and cleaner to hide this global value behind an exported function in a DLL.
source to share