Solved

How CWinThread derived class can get messages ?

Posted on 2002-03-22
7
807 Views
Last Modified: 2013-11-20
Hi

I've created a class 'CSecondClass' that is derived by 'CFirstClass', which is derived by CWinThread.

I want that CSecondClass will get a custom messages
(e.g. WM_USER+19)

I've tried to do it by a message map :

#define TM_MYTHREAD_MESSAGE WM_USER+19

BEGIN_MESSAGE_MAP(CSecondClass,CFirstClass)
  ON_THREAD_MESSAGE(TM_MYTHREAD_MESSAGE,
                     OnMyThreadMessageHandler)
END_MESSAGE_MAP()

The problem is that the compiler writes :

'type cast' : cannot convert from 'long (__thiscall CSecondClass::*)(unsigned int,long)' to
'void (__thiscall CWinThread::*)(unsigned int,long)'

Please tell me, how to use the message map, that my class will can get the wanted message without getting any error about converting (CSecondClass::*)(unsigned int,long) to (CWinThread::*)(unsigned int,long)'.


Thanks
Michael
0
Comment
Question by:MichaelMaromm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 6888424
Hi,

Just change ur thread function's return datatype from long to void and check it.

It will be helpfull if u post some relevant code of thread function declaration here.

Try it out.
VinExpert
0
 

Author Comment

by:MichaelMaromm
ID: 6888612
Hi VinExpert

I changed the returned data type as you suggested, but now the compiler's errors are :

error C2440: 'type cast' : cannot convert from
'void(__thiscall CThreadWriteInControl::*)
(unsigned int,long)' to 'void (__thiscall CWinThread::*)(unsigned int,long)'

 error C2440: 'type cast' : cannot convert from 'void (__thiscall CThreadWriteInControl::*)(unsigned int,long)' to
'void (__thiscall CWinThread::*)(void)'
 Pointers to members have different representations; cannot cast between them.
---------------------------------------------------------

The message map is :
BEGIN_MESSAGE_MAP(CThreadWriteInControl,CThreads)
   ON_THREAD_MESSAGE(TM_ITEMARRIVED,OnItemArrived)
END_MESSAGE_MAP()

When CThreadWriteInControl is derived by CThreads, which is derived by CWinThread.

The OnItemArrived is declared in 'CThreadWriteInControl'
as the follows :

afx_msg virtual void OnItemArrived
(WPARAM wParam,LPARAM lParam) {}

This function member is implemented in other classes that are derived by CThreadWriteInControl.


Please tell me, How to fix it.

Michael
0
 
LVL 1

Expert Comment

by:pcj0961
ID: 6889320
Is your thread a user interface or worker threads.  worker threads don't have message pumps.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:Chandra V
ID: 6890346
The standard convention for a message handler is

LRESULT YourClass::YourHandler(WPARAM wParm,LPARAM lParm)

This is strict in VC 7.0

If you are using VC 6.0

you can use

void YourClass::YourHandler()
(or)
void YourClass::YourHandler(WPARAM wParm, LPARAM lParm)

0
 

Author Comment

by:MichaelMaromm
ID: 6891077
Hi cvallabhaneni,

Thanks for your answer, but when I try to use:

void MyClass::MyHandler(WPARAM wParm, LPARAM lParm)

I get the compiler error :

'type cast' : cannot convert from
'void(__thiscall CMyClass::*)
(unsigned int,long)' to 'void (__thiscall CWinThread::*)(unsigned int,long)'.

By The Way : 'CMyClass' is derived by 'COtherClass', which is derived by 'CWinThread'.

Michael


0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6904948
PLEASE RESPOND HERE TO MICHAEL'S LAST INPUT SO WE CAN FINALIZE THIS.

MOONDANCER - EE MODERATOR
0
 

Accepted Solution

by:
jubjub2 earned 50 total points
ID: 7240396
i just had the same problem MichaelMaromm.
To fix it, you have to make sure the Function that will be called when the thread is sent that messages, returns a void.

Both in the header and in the cpp.

It fixed it in my case.

.h
afx_msg void OnBlah(WPARAM wParam, LPARAM);

.cpp

BEGIN_MESSAGE_MAP(CBlahThread, CWinThread)
//}}AFX_MSG_MAP
ON_THREAD_MESSAGE(WM_BLAHMSG, OnBlah)
END_MESSAGE_MAP()

void CBlahThread::OnBlah(WPARAM wParam, LPARAM lParam)
{
  // Do your work
}
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
format the code in java 6 116
child constructor and parent constructor, overriding and overloading 6 95
Thin secure Windows 10 5 116
Increment column based of a FK 8 68
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question