Interesting error (C++)...

Started by
9 comments, last by Dave Hunt 18 years, 10 months ago
I'm sorry, I feel like an idiot for not being able to solve this... Anway, first feast your eyes on this:

// ...

class xrMessagePump
{
public:
	static void SendMessage(xrMessagePtr Message);
	static void SendMessage(int DestID, xrPtr<xrClass> Sender, string Message, float Delay, int Priority, boost::any Arg1);
        // ...     
};

// in a completely different file, many light years away...

void WorldMap::CALLBACK_Render::Function(xrMessagePtr Msg, xrClass* Parent)
{

	WorldMap* parent = static_cast<WorldMap*>(Parent);

	xrMessagePump::SendMessage(parent->m_WaterTiles->GetUID(), this, "RepeatingTileMap_Render", 0.0f, xrMessage::MESSAGE_PRIORITY_IMMEDIATE, NULL);

        // ^^ this line is the culprit.
}


The marked line is causing these errors:
Quote: c:\Documents and Settings\Owner\My Documents\Code\Projects\War of the Seas\WorldMap.cpp(48): error C2039: 'SendMessageA' : is not a member of 'xrMessagePump' c:\Documents and Settings\Owner\My Documents\Code\Projects\War of the Seas\MessageSystem.hpp(117) : see declaration of 'xrMessagePump' c:\Documents and Settings\Owner\My Documents\Code\Projects\War of the Seas\WorldMap.cpp(48): error C2660: 'SendMessageA' : function does not take 6 arguments
This has thoroughly confused me. For one thing, why is there an 'A' appended to the function name? And why are those errors even being thrown? I call the same function with nearly identical parameters elsewhere in the code without getting any errors. For example, this code compiles fine:

xrMessagePump::SendMessage(m_CurrMap->GetUID(), this, "Map_Render", 0.0f, xrMessage::MESSAGE_PRIORITY_PERIODIC, NULL);
And as for the second error, I think it's just a consequence of the first, since the function does indeed take 6 parameters. Anyway, can someone please help me out here? I feel as if I'm overlooking something obvious, but I'm not sure... Thanks for your time!
Advertisement
To provide support for both ASCII and Unicode application, Win32 has macros that remaps text-manipulating functions like SendMessage to SendMessageA and SendMessageW (I think). With a few additional conventions to follow (e.g. TCHAR), you don't have to modify your application to recompile it with Unicode support.

Macros are dumb. They do not differenciate between their intended target and an identically named member function (it's just raw text substitution).

Name your function differently or undefine the macro.

Macros are evil.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
You just have a naming conflict. SendMessage is a window macro, See winuser.h
SendMessage is #defined in by windows.h to be either SendMessageA or SendMessageW depending on whether you're using unicode or not. Basically, you can either rename your function, or #undef SendMessage for that file.

tj963
tj963
This has to do with the Windows headers having #defines for every function that is impacted by Unicode/Non-Unicode. Based on a #ifdef, if Unicode is being used, SendMessage is #define'd as SendMessageW. If Unicode is not being used, then it is defined as SendMessageA.

So, if you have any functions/methods with the same name as one of those Windows functions, the #define's will affect them and any calls to them, too.

The only way around this is to make sure you don't name your functions/methods the same as any Windows API functions.

edit - boy, aren't we all johnny on the spot.
macros! winuser.h! rename!
Thanks for the speedy replies!

Wow, the Win32 API sucks. Now I remember why I swore never to touch it again a long time ago.

Anyway, I just renamed the function from 'SendMessage' to 'AddMessage' (because, apparently, 'PostMessage' was also used by Win32 [razz]) and that fixed it.
for all your renaming needs :D
http://thesaurus.reference.com/search?q=send
hmmm....i like "hurry off"....ya, HurryOffMessage, that rocks.

This topic is closed to new replies.

Advertisement