Use dll with LoadLibrary () method in C ++

Can the LoadLibrary method be used to import data of type struct? Sorry for my english. thank.

+1


source to share


5 answers


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 is struct

    !) 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.

+8


source


Do you want to put data in a dll and use LoadLibrary and Getprocaddres to get a pointer to the data? This is possible, although more often than not, putting functions in dlls and letting them return a pointer to data.



+3


source


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.

+2


source


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"

+1


source


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.

0


source







All Articles