DLL mangling function name

Started by
1 comment, last by DanG 21 years, 9 months ago
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?
Ambassador: Mr. Bush are you stoned or just really, REALLY dumb?Pres. Bush - I assure you I am not stoned.
Advertisement
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.
---visit #directxdev on afternet <- not just for directx, despite the name
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.

This topic is closed to new replies.

Advertisement