tags:

views:

2076

answers:

5

Can I use LoadLibrary method for to import a data of type struct?? excuse me for my English. thanks.

+2  A: 

Hm ... That question was a bit hard to understand, I'm afraid.

In C++, a struct declaration is just that, a declaration. It does not generate something you can load at run-time, it's a pure compile-time construction that just tells the compiler how something is laid out in memory, the fields involved, their types and order, and so on.

unwind
+1  A: 

I assume that you are using VC++ 2005.

MS now providing you Delay Loading Dll's.

The Visual C++ linker now supports the delayed loading of DLLs. This relieves you of the need to use the Windows SDK functions LoadLibrary and GetProcAddress to implement DLL delayed loading.

Steps to follow in order to setup the Delay Load.

Goto to Project->Properties->Linker->Input and then specify your Dll in 'Delay Loaded DLLs'

mahesh
If he wants to load libraries dynamically based on versioning and availability, then LoadLibrary must still be used.
Johann Gerell
Thanks for that. I didn't knew this one.
mahesh
+3  A: 

Do you mean to put data in a dll, and use LoadLibrary and Getprocaddres to get a pointer to the data? That is possible, although it is more common to put functions in a dll, and let them return a pointer to the data.

Wimmel
+6  A: 

Let me assume some things that are left out in the question:

  1. You have a dynamic library called flubber.dll
  2. The library exports the function bool GetFlubber(Flubber& flubber).
  3. The function and the type Flubber (which just happens to be a struct!) are declared in a header file called flubber.h.

If those 3 conditions are met, then you can use LoadLibrary on flubber.dll, followed by GetProcAddress with GetFlubber as proc name, and finally you can declare a Flubber instance locally and pass it to GetFlubber via the retrieved proc address.

Johann Gerell
A: 

As other responses have suggested it's hard to tell what's being asked here, but I'll throw in a response for another interpretation of the question. I'm not sure if it's "officially supported", but you can have a DLL export a global variable and then dynamically access it via GetProcAddress.

For instance, if a library called foo.dll contains a global of type FOO named g_MyGlobal, then it can export the variable in foo.def. Client code can then call:

MyPointer = GetProcAddress(..., "g_MyGlobal");

and get a "FOO *" pointer to the global.

...but with that said, if you find yourself needing to do this for something other than private testing purposes, you might want to re-think your design. It would probably be much safer and cleaner to hide this global behind an exported function in the DLL.

Reuben