473,671 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with BEGIN_TEMPLATE_ MESSAGE_MAP (long)

Hi,

Consider the following code:

---

template <class T>
class TMyCWndWrapper : public T
{
public:
afx_msg void OnEnable(BOOL bEnable)
{
// For the sake of simplicity I'll just call the base class imp.
T::OnEnable(bEn able);
}

DECLARE_MESSAGE _MAP()
};

// Define a custom template IMPLEMENT_MESSA GE_MAP
#define WND_TEMPLATE_IM PLEMENT_MESSAGE _MAP(baseClass) \
BEGIN_MESSAGE_M AP(TMyCWndWrapp er< baseClass >, baseClass) \
ON_WM_ENABLE() \
END_MESSAGE_MAP ()
WND_TEMPLATE_IM PLEMENT_MESSAGE _MAP( CListBox );
WND_TEMPLATE_IM PLEMENT_MESSAGE _MAP( CListCtrl );

---

This code compiles just fine in VC6.
In VC8, I get the following error:
error C2906: 'const AFX_MSGMAP
*TMyCWndWrapper <T>::GetThisMes sageMap(void)' : explicit specialization
requires 'template <>'

So I went on and implemented my own BEGIN_TEMPLATE_ MESSAGE_MAP and
added the "template <>" where needed.

When I compiled, I had a macro redefinition on
BEGIN_TEMPLATE_ MESSAGE_MAP. It turns out that MFC already took care of
that, so I removed my implementation and used MFC's with the adjusted
line:
BEGIN_TEMPLATE_ MESSAGE_MAP(TMy CWndWrapper, baseClass , baseClass)

Now, if I define only the first line:
WND_TEMPLATE_IM PLEMENT_MESSAGE _MAP( CListBox );

The code actually compiles, but if I add the other line:
WND_TEMPLATE_IM PLEMENT_MESSAGE _MAP( CListCtrl );

Now I get the error:
error C2995: 'const AFX_MSGMAP *TMyCWndWrapper <T>::GetMessage Map(void)
const' : function template has already been defined.
My current status is that I re-implemented BEGIN_TEMPLATE_ MESSAGE_MAP
as follows:

---
#undef BEGIN_TEMPLATE_ MESSAGE_MAP
#define BEGIN_TEMPLATE_ MESSAGE_MAP(the Class, type_name, baseClass) \
PTM_WARNING_DIS ABLE \
template <\
const AFX_MSGMAP* theClass< type_name >::GetMessageMa p() const \
{ return GetThisMessageM ap(); } \
template <\
const AFX_MSGMAP* PASCAL theClass< type_name >::GetThisMessa geMap() \
{ \
typedef theClass< type_name ThisClass; \
typedef baseClass TheBaseClass; \
static const AFX_MSGMAP_ENTR Y _messageEntries[] = \
{
---

The diff. between this one and MFC's is that I replaced:
template < typename type_name >
with:
template <>

---

The code now compiles just fine.
So, in case this helps someone, I'll be very happy.
Beyond that, if someone would like to explain what's going on here I
will be happy to receive an answer.
I don't understand what "template < typename type_name >" means.

Cheers.

Dec 13 '06 #1
3 4427
---
#undef BEGIN_TEMPLATE_ MESSAGE_MAP
#define BEGIN_TEMPLATE_ MESSAGE_MAP(the Class, type_name, baseClass) \
PTM_WARNING_DIS ABLE \
template <\
const AFX_MSGMAP* theClass< type_name >::GetMessageMa p() const \
{ return GetThisMessageM ap(); } \
template <\
const AFX_MSGMAP* PASCAL theClass< type_name >::GetThisMessa geMap() \
{ \
typedef theClass< type_name ThisClass; \
typedef baseClass TheBaseClass; \
static const AFX_MSGMAP_ENTR Y _messageEntries[] = \
{
---

The diff. between this one and MFC's is that I replaced:
template < typename type_name >
with:
template <>

---

The code now compiles just fine.
So, in case this helps someone, I'll be very happy.
Beyond that, if someone would like to explain what's going on here I
will be happy to receive an answer.
I don't understand what "template < typename type_name >" means.
The difference is that your code implements a single specialized message map
each time, whereas the library code declares an entire family of message
maps using a template parameter. With the library version, you aren't
actually specifying what the base class is... instead you are giving a name
to the base class which can be used inside the message map to declare
functions that use the base class, whatever it may be, in the argument list
or return type.
>
Cheers.

Dec 13 '06 #2
Ben Voigt wrote:
>
The difference is that your code implements a single specialized message map
each time, whereas the library code declares an entire family of message
maps using a template parameter. With the library version, you aren't
actually specifying what the base class is... instead you are giving a name
to the base class which can be used inside the message map to declare
functions that use the base class, whatever it may be, in the argument list
or return type.
I'm doing my best to understand what you wrote, but I'm having a hard
time connecting it to real life.
Can you please give a usage example to MFC's version of the macro? I'm
just missing its purpose.
Also, am I on the right track, or do you have a better idea for me to
solve my issue using standard macros instead of redefining it?

TIA.

Dec 14 '06 #3

<no********@gma il.comwrote in message
news:11******** *************@j 72g2000cwa.goog legroups.com...
Ben Voigt wrote:
>>
The difference is that your code implements a single specialized message
map
each time, whereas the library code declares an entire family of message
maps using a template parameter. With the library version, you aren't
actually specifying what the base class is... instead you are giving a
name
to the base class which can be used inside the message map to declare
functions that use the base class, whatever it may be, in the argument
list
or return type.

I'm doing my best to understand what you wrote, but I'm having a hard
time connecting it to real life.
Can you please give a usage example to MFC's version of the macro? I'm
just missing its purpose.
Also, am I on the right track, or do you have a better idea for me to
solve my issue using standard macros instead of redefining it?
You have something along these lines you wrote:

// Define a custom template IMPLEMENT_MESSA GE_MAP
#define WND_TEMPLATE_IM PLEMENT_MESSAGE _MAP(baseClass) \
BEGIN_MESSAGE_M AP(TMyCWndWrapp er< baseClass >, baseClass) \
ON_WM_ENABLE() \
END_MESSAGE_MAP ()
WND_TEMPLATE_IM PLEMENT_MESSAGE _MAP( CListBox );
WND_TEMPLATE_IM PLEMENT_MESSAGE _MAP( CListCtrl );
With the MFC map, you get the per-class repetition for free as part of the
template behavior, no macro needed.

BEGIN_TEMPLATED _MESSAGE_MAP(TM yCWndWrapper, baseClass, baseClass) \
ON_WM_ENABLE()
END_MESSAGE_MAP ()

defines the message map for TMyCWndWrapper< baseClassfor all needed values
of baseClass. The compiler will instantiate the template for both
TMyCWndWrapper< CListBoxand TMyCWndWrapper< CListCtrlif you have used them
anywhere. This is far better than the macro because: it is type-safe and
error reporting is far better, and there is no need to maintain the list of
instances.

or to see why there need to be three arguments instead of two, add to the
above:
template <typename T>
class TMyDerivedWnd : TMyCWndWrapper< T{};

BEGIN_TEMPLATED _MESSAGE_MAP(TM yDerivedWnd, baseClass,
TMyCWndWrapper< baseClass>) \
ON_WM_ENABLE()
END_MESSAGE_MAP ()

>
TIA.

Dec 15 '06 #4

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

Similar topics

1
1262
by: sajidazmi | last post by:
Hi, I'm coding an Stock Order Entry System. The problem I'm facing is when I'm passing a pointer to one class, the pointer gets corrupted. I'm not able to see why? Here is the code, please tell me what I'm doing wrong. Problem are marked as <== in the code. /** Class Header **/ /* * Symbol
4
1914
by: MrTang001 | last post by:
How I can fix this problem? I don't know why it alway prompted (first use this function). I have use newDollars, newCents... to access the base class member variable. And the member functions for Initialize() and Print(), is it function overloading? it already have this functions in the base class. Pls let me know what problem of its! Thx ------------------------------------------------------------------ Result
1
4236
by: Rohit Raghuwanshi | last post by:
Hello all, we are running a delphi application with DB2 V8.01 which is causing deadlocks when rows are being inserted into a table. Attaching the Event Monitor Log (DEADLOCKS WITH DETAILS) here. From the log it looks like the problem happens when 2 threads insert 1 record each in the same table and then try to aquire a NS (Next Key Share) lock on the record inserterd by the other thread. Thanks Rohit
6
2431
by: Uttam | last post by:
Hello, I am using the code from Chapter 17 specifically the code from the font frmListFonts in my application. I have taken care to copy all the relevant modules / class modules into the respective files / folders etc. Nevertheless, I get the following error when I start my application: Compile error; Sub or Function not defined
0
3932
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
39
19620
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1) What's the difference between these 3 statements: (i) memcpy(&b, &KoefD, n); // this works somewhere in my code
7
5212
by: Camellia | last post by:
hi all, I wrote a "table of powers" program and made the 5th power the highest, but when I tried to run the program I found a problem. Here's the output: Integer Square power 3rd power 4th power 5th ------- ------ --------- --------- --------- 1 1 1 1 1
8
2164
by: Aereshaa | last post by:
For some reason, when I compile this code: int main(){ char* a = malloc(5); long* l = (*long) a; } //I shortened it to isolate the problem. I get this error: error.c:3: error: expected expression before ‘long’
1
2659
by: Alex Vinokur | last post by:
Hi, I have compilation problem on SUN CC compiler with template while using option -m64 (64-bit addressing model). No problem while using option -m32 (32-bit addressing model) $ CC -V CC: Sun C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25
0
8483
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8824
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8603
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7444
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6236
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.