DLL hell !!

This topic is 4338 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I am trying to code a simple DLL written in C++, I have exported by function by declaring it: __declspec(dllexport) testFn( void ) However, if I compile with a MAP file with exports listed, then I can see that C++ is still mangling the name - how can I stop this happening ? I am currently tearing great chunks of hair out with this! Cheers.

Share on other sites
Surround your function and it's declaration with extern "C" like this:
extern "C" {   __declspec(dllexport) testFn( void );}

Share on other sites
Thanks - that worked ( I can now patch up my scalp... )

Share on other sites
- Problem now is that if I pass a parameter to the DLL I get a rubn time error
with ESP register, obviously something about the stack and the parameters with
the call in the application not matching that of the DLL... guess I'll sort it
out eventually, but if you know what the corressponding call should like like then it would certainly help....
cheers

Share on other sites
The question is, are you linking against the DLL or are you loading it at runtime? The thing is, that if you are not actually linking against the DLL, the runtime loader will not load the library and if you do not load it manually you try to call a function that is not in memory.

But since you are trying to access the symbol I assume that you are trying to load it manually at runtime...

I have never had problems with DLLs if you link against them, except that you have to write the rather nasty __declspec(dllexport) / __declspec(dllimport) before every symbol you want to link against.

What I do for DLLs is the following:

In some header file like config.hpp I put

#if defined __WIN32__
# if defined BUILD_DLL
# define API_EXPORT __declspec(dllexport)
# else
# define API_EXPORT __declspec(dllimport)
# endif
#endif

I put API_EXPORT before all of my symbols that I need to export. That is before classes and public functions. During the build process I define BUILD_DLL and all works fine. I normally add a prefix to all, so it does not conflict with other DLLs.

And yes this is only an issue on windows systems.

The only problem that remains is symbol lookup. If you try to manually load something out of a DLL you need to use the extern "C" declaration since the C++ compiler will mangle your symbols. Even worse, compilers to not agree on how to mangle the symbols, so even if you find a clever way mangle your query on the fly you are stuck. By the way, you can put the extern "C" before a function without the braces.

But I must say, I seldom have the need for manually loading DLLs, so mangling is not really a issue.

Share on other sites
Make sure you have the right calling convention you are probably importing it in __stdcall.

__declspec(dllexport) __stdcall testFn( void );

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• Forum Statistics

• Total Topics
633767
• Total Posts
3013734
×