Interesting error (C++)...

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

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 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 on other sites
You just have a naming conflict. SendMessage is a window macro, See winuser.h

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 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 on other sites
macros! winuser.h! rename!

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 on other sites
for all your renaming needs :D

Share on other sites
http://thesaurus.reference.com/search?q=send

Share on other sites
hmmm....i like "hurry off"....ya, HurryOffMessage, that rocks.

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 31
• 16
• 11
• 10
• Forum Statistics

• Total Topics
634118
• Total Posts
3015609
×