473,379 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Help! Windows.h Conflict

Hi all,

I have a class which contains a method called GetMessage(). When I
compile and unit test it all is well.

However in the application I want to use it in there appears to be a
conflict with Windows.h. I receive the following error:

Error 1 error LNK2001: unresolved external symbol "public: class
Messaging::Native::IMessage * __thiscall
Messaging::Native::MessageEvent::GetMessageW(void) "
(?GetMessageW@MessageEvent@Native@Messaging@@QAEPA VIMessage@234@XZ) Program.obj

As far as I can tell this is due to the following definition in
Windows.h which is causing the linker to convert my GetMessage() method
call to GetMessageW(). The line which causes this is as such:

_message = notification->GetMessage(); (notification is a
MessageEvent*)

And I think the linker is trying to do ->GetMessageW(); because of:

#define GetMessage GetMessageW

Which is included in one of the includes from Windows.h. I am using
Unicode so I cannot turn unicode off but then I guess it would still
have problems as it would then translate to GetMessageA();

I do not want to have to rename my method because of this. How can I
get remove this conflict? I would of thought that the definition would
only affect the global namespace but alas I must be wrong.

Kind Regards,
Mark

Dec 22 '05 #1
5 2907
quortex wrote:
I have a class which contains a method called GetMessage(). When I
compile and unit test it all is well.
Props for writing unit tests! (If that's what you mean;)
However ... Windows.h ... GetMessageW ... #define GetMessage GetMessageW I do not want to have to rename my method because of this. How can I
get remove this conflict? I would of thought that the definition would
only affect the global namespace but alas I must be wrong.


Sorry - MS's cute trick always bites us one way or the other. And #define
things never obey C++ scope. That's one big reason to avoid writing your
#define lines. MS can't follow that rule because they must port to C, which
has fewer alternatives.

Try this:

#include <windows.h>
#undef GetMessage

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Dec 22 '05 #2
Hi,

Thanks for the reply. Yes I am writing unit tests, Test Driven
Development in fact ;)

I already tried the #undef GetMessage actually. In fact I was
bewildered by the result:

Error 5 error C2039: 'GetMessage' : is not a member of
'Messaging::Native::MessageEvent'
d:\my data\development\messaging.native.test\program.cpp 28

Surely #undef GetMessage shouldn't undefine my member just ignore the
previous definition.

Windows.h is included by a few header files so I put the #undef only at
the top of the file causing problems although after all the includes so
should be correct IMO.

I am stumped :(

Thanks,
Mark

Dec 22 '05 #3

qu*****@hotmail.com wrote:
Hi all,

I have a class which contains a method called GetMessage(). When I
compile and unit test it all is well.

However in the application I want to use it in there appears to be a
conflict with Windows.h. I receive the following error:

Error 1 error LNK2001: unresolved external symbol "public: class
Messaging::Native::IMessage * __thiscall
Messaging::Native::MessageEvent::GetMessageW(void) "
(?GetMessageW@MessageEvent@Native@Messaging@@QAEPA VIMessage@234@XZ) Program.obj

As far as I can tell this is due to the following definition in
Windows.h which is causing the linker to convert my GetMessage() method
call to GetMessageW(). The line which causes this is as such:

_message = notification->GetMessage(); (notification is a
MessageEvent*)

And I think the linker is trying to do ->GetMessageW(); because of:

#define GetMessage GetMessageW

Which is included in one of the includes from Windows.h. I am using
Unicode so I cannot turn unicode off but then I guess it would still
have problems as it would then translate to GetMessageA();

I do not want to have to rename my method because of this. How can I
get remove this conflict? I would of thought that the definition would
only affect the global namespace but alas I must be wrong.


Unfortunately, macros do not respect scope or namespaces or the type
system. They cannot since those concepts are only meaningful to the
compiler and macro substitution is done by the preprocessor, not the
compiler. Your experience is exactly why macros are evil.

Assuming you need to include "windows.h" at all in your program, can
you move your code that uses your GetMessage function into a separate
source file that doesn't #include "windows.h"? That will probably
depend on how widely you use your GetMessage function. If not, I can't
think of anything right now other than renaming your function.

Gavin Deane

Dec 22 '05 #4

qu*****@hotmail.com wrote:
Hi,

Thanks for the reply. Yes I am writing unit tests, Test Driven
Development in fact ;)

I already tried the #undef GetMessage actually. In fact I was
bewildered by the result:

Error 5 error C2039: 'GetMessage' : is not a member of
'Messaging::Native::MessageEvent'
d:\my data\development\messaging.native.test\program.cpp 28

Surely #undef GetMessage shouldn't undefine my member just ignore the
previous definition.

Windows.h is included by a few header files so I put the #undef only at
the top of the file causing problems although after all the includes so
should be correct IMO.

I am stumped :(


Just a guess...

Did you #undef GetMessage before your class definition, the
implementation of the class *and* everywhere you use the class?

If your class definition was compiled with the GetMessage macro visible
then it would actually declare a member function called GetMessageW.
Then your client code (compiled with the GetMessage macro #undef'd)
would try and call a non-existent function called GetMessage, which
would yield the compiler error you see.

Gavin Deane

Dec 22 '05 #5
On 22 Dec 2005 08:44:43 -0800, qu*****@hotmail.com wrote:
Hi all,

I have a class which contains a method called GetMessage(). When I
compile and unit test it all is well.

However in the application I want to use it in there appears to be a
conflict with Windows.h. I receive the following error:

Error 1 error LNK2001: unresolved external symbol "public: class
Messaging::Native::IMessage * __thiscall
Messaging::Native::MessageEvent::GetMessageW(void )"
(?GetMessageW@MessageEvent@Native@Messaging@@QAEP AVIMessage@234@XZ) Program.obj

As far as I can tell this is due to the following definition in
Windows.h which is causing the linker to convert my GetMessage() method
call to GetMessageW(). The line which causes this is as such:

_message = notification->GetMessage(); (notification is a
MessageEvent*)

And I think the linker is trying to do ->GetMessageW(); because of:

#define GetMessage GetMessageW

Which is included in one of the includes from Windows.h. I am using
Unicode so I cannot turn unicode off but then I guess it would still
have problems as it would then translate to GetMessageA();

I do not want to have to rename my method because of this. How can I
get remove this conflict? I would of thought that the definition would
only affect the global namespace but alas I must be wrong.

Kind Regards,
Mark


I also program for Windows OS, and I have met this problem so many
times, that finally, I have reached a coding style thta works nice:
All functions will start with a lower case letter (i.e. getMessage
instead of GetMessage).

MS uses exactly the opposite style, so that I have two benefits: no
name clashing with MS *and* easy identificaction os OS functions at
first sight.

Best regards

Zara
Dec 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
4
by: dixie | last post by:
Help, I'm really out of my depth here (not unusual I hear you say :-). I have just installed HTML Help in an application. I told it in the Project Properties the path to the help file. I then...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.