Re: Register my own messages
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 22 Jan 2008 17:36:27 -0500
Another alternative is to declare it in the header file as
static const int UWM_WHATEVER = ::RegisterWindowMessage(...);
which is a bit of a cheat but is easy to use, and works correctly. The trick is to not
include the header file except in the modules that actually use it.
joe
On Mon, 21 Jan 2008 10:32:04 -0600, "Doug Harrison [MVP]" <dsh@xxxxxxxx> wrote:
On Mon, 21 Jan 2008 08:10:29 -0800 (PST), clinisbut <clinisbut@xxxxxxxxx>Joseph M. Newcomer [MVP]
wrote:
I'm trying to understand how to work with my own defined messages.
I've readed the essays from http://www.flounder.com/mvp_tips.htm which
I'm sure is very complet, is too technical for my level.
I found an example at http://www.codersource.net/mfc_user_event.html
but doesn't seems to work... I'm getting this error:
"int CODERSOURCEMSG" (?CODERSOURCEMSG@@3HA) already defined in
PostMessage01.obj
Debug/PostMessage01.exe : fatal error LNK1169: one or more multiply
defined symbols found
I defined int CODERSOURCEMSG in a header file appart. I don't
understand why vc is saying thats a duplicate declaration...
An object may be declared many times, but it can only be defined once. The
definition is what gives it storage and may contain an initializer, while
the declaration merely declares its type and name so that it can be used. A
definition is always a declaration, but the reverse doesn't necessarily
hold. It sounds like your header file contains a definition, so every file
that #includes the header defines this int, and because it isn't declared
static, the linker complains about multiple definitions. To fix it, use
extern in the header file:
extern const int UWM_MYMSG;
And in one .cpp file, write:
const int UWM_MYMSG = RegisterWindowMessage(...);
This defines UWM_MYMSG in one and only one place, but the declaration in
the header file allows anyone who #includes the header to use it. Since its
value will never change, I also declared it const.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: Register my own messages
- From: Doug Harrison [MVP]
- Re: Register my own messages
- References:
- Register my own messages
- From: clinisbut
- Re: Register my own messages
- From: Doug Harrison [MVP]
- Register my own messages
- Prev by Date: Re: char array problem
- Next by Date: Re: Register my own messages
- Previous by thread: Re: Register my own messages
- Next by thread: Re: Register my own messages
- Index(es):
Relevant Pages
|