Solved

How CWinThread derived class can get messages ?

Posted on 2002-03-22
7
792 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
7 Comments
 
LVL 8

Expert Comment

by:VinExpert
Comment Utility
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
Comment Utility
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
Comment Utility
Is your thread a user interface or worker threads.  worker threads don't have message pumps.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 2

Expert Comment

by:Chandra V
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now