Sign in to follow this  
nilkn

Interesting error (C++)...

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this