Compilation of a dll that accesses another dll

So I have an interesting problem. I work with my own dll sets, which obviously I have no source. The goal is to write an intermediate dll that groups together a large chain of funnction calls from proprietary dlls. The problem that occurs when compiling with g ++ is that I get errors for the source dlls line by line: cannot export libname_NULL_THUNK_DATA. Symbol not found.

If I add the main one and just compile the executable, everything will work as expected. I use mingw to compile. Thanks for any help.

In response to the first answer: Either I am embarrassed by what you say, or I did not formulate my question very well. I am not trying to explicitly export anything from my shell. I just call functions from my DLLs. The problem is that I get errors that it cannot export these specific characters from the dll to my shell. The problem is that I'm not even quite sure what these _NULL_THUNK_DATA characters are for. I did a search and read somewhere that they should not be exported because they are internal characters that windows use. I tried using the -exclude-symbols directive for the linker, but it did nothing. I apologize if I do not completely understand what you are trying to say.

So, I think my problem was related to this. When you simply compile a standard executable that uses the DLL, I was able to include headers and directly call functions, for example:

#include :3rdparty.h int main(){ dostuff(); // a function in the 3rdparty.dll } 

this will compile and work fine. I just needed to link the libraries in the g ++ command. When binding with the -shared flag, I would get these errors (with the main remote of course). I think this is due to the fact that by default g ++ tries to import all the characters from the dll. I did not understand why this is happening in the dll vs in the executable. I will try to do this using GetProcAddress (). Thanks!

+4
source share
2 answers

it should be as simple as you think.

for example: your dll code needs:

 void doStuff() { 3rdparty.login(); 3rdparty.dostuff(); 3rdparty.logoff(); }; 

so far - it's so good that you included the correct headers .... (if you have them, if you don't, you need to import the library using LoadLibrary (), and then create a pointer to each exported dll entry point with using GetProcAddress () and then calling that function pointer)

Then you contact the third party lib and that. Sometimes you will have to wrap the definitions with "extern" C "'to correctly change the correct name of the link.

As you say, you are using g ++, you cannot be confused with __declspec (dllimport), which is an extension of MS VC.

+2
source

Compilation tells me that you are approaching this from the wrong end. Your DLL does not have to export its own wrapper functions, but directly refers to export from other DLLs.

eg. in the Windows Kernel32.DEF file, the following forward exists:

  EXPORTS
    ...
    HeapAlloc = NTDLL.RtlAllocHeap

There is no code for the HeapAlloc function.

0
source

All Articles