• ### Popular Now

• 10
• 10
• 12
• 12
• 14

#### Archived

This topic is now archived and is closed to further replies.

# DLL mangling function name

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

## Recommended Posts

I am writing my first DLL and i keep getting a very strange compiling error. My DLL currently has one function, OnInitialize(IEngine * engine). IEngine is a class present in the .exe that calls the dll. In the .exe the code calls the function pointer set to OnInitialize and passes in (this). In the DLL there is a hidden global variable called IEngine * Engine. In OnInitialize there is this code: Engine->SendMessage(/* params*/); This is the only line that calls an Engine function. Before adding this the DLL compiled and was used by the .exe just fine. Now when i compile with this line OR any Engine call, I get a compiler warning: error C2039: ''SendMessageA'' : is not a member of ''IEngine'' see declaration of ''IEngine'' any line i write to call on Engine, such as Engine->GetObject(), seems to automatically get an "A" attached to it. If however i purposely mispell the function, such as Engine->GetObjectB(), the error becomes: error C2039: ''GetObjectB'' : is not a member of ''IEngine'' see declaration of ''IEngine'' Its like the compiler won''t let me write the correct name to the function. What in the world could be causing this? Is what i am trying to do (access a class inside the calling .exe) illegal?

##### Share on other sites
quote:
Original post by DanG
What in the world could be causing this?

Unicode. A large part of Windows functions are implemented in ANSI and Unicode versions. Here''s some stuff from winuser.h:

  WINUSERAPILRESULTWINAPISendMessageA(    IN HWND hWnd,    IN UINT Msg,    IN WPARAM wParam,    IN LPARAM lParam);WINUSERAPILRESULTWINAPISendMessageW(    IN HWND hWnd,    IN UINT Msg,    IN WPARAM wParam,    IN LPARAM lParam);#ifdef UNICODE#define SendMessage  SendMessageW#else#define SendMessage  SendMessageA#endif // !UNICODE

As you see, there are two versions of SendMessage. First one is desigend for ANSI character set while the second one is written for Unicode. A and W are appended to the end of function name, respectively, to distinguish between them. SendMessage is defined to one of these depending on your project settings, namely whether you have UNICODE defined.

Solution? Don''t use Win32 function names in your classes or always include the same set of Win32 headers in all source files. In your case, try including windows.h in all your sources, even if you aren''t using anything from there.

##### Share on other sites
quote:
Solution? Don''t use Win32 function names in your classes or always include the same set of Win32 headers in all source files. In your case, try including windows.h in all your sources, even if you aren''t using anything from there.

If you include the windows header files everywhere, then your functions will still be "renamed" and your interfaces will be modified against your will. This is almost certainly not a good solution. You''d better change the method names so that they don''t conflict with these silly Win32 defines.