Link to home
Start Free TrialLog in
Avatar of j_madhavi
j_madhavi

asked on

How to send user defined structure using PostMessage?

Hello,

I am trying to send a structure using PostThread message.
My structure is of the form:
typedef DATA
{
int EventID;
CString ModuleName;
CString ThreatName;
} info;

info info_data;
PostMessage(WM_MYMSG, (info_data&)wParam,NULL);

In the recieving thread I tried this way:
info_data = (info_data&)wParam; // I am getting runtime error here.

Can anyone please help me to pass a user defined structure using PotMessage?

Thanks
Madhavi
Avatar of Vinayak Kumbar
Vinayak Kumbar

Hi,

The way u r trying out is fine... but u need to change ur postmessage as below:

info info_data;
/* Fill in values in info_data - optional */
PostMessage(WM_MYMSG, (info_data&)info_data, NULL);

Now try to get it back.

Try it out.
VinExpert
Avatar of j_madhavi

ASKER

Hi,

Thanks for the help.
 When I tried this way,
typedef struct LOG_DATA
{
      CString timeStamp;
      int SequenceNo;
      long EventId;
      int ThreatID;
      CString ModuleName;
      int ModuleId;
      CString ErrorInfo;
      
}LOG_VIEW_DATA;
LOG_VIEW_DATA  is my structure
LOG_VIEW_DATA data = (LOG_VIEW_DATA)*aIterator;//here the structure gets filled
AfxGetMainWnd( )->PostMessage(WM_LOGMSG,  (LOG_VIEW_DATA&)data , 0) ;
I got an error msg saying
error C2664: 'CWnd::PostMessageA' : cannot convert parameter 2 from 'LOG_VIEW_DATA' to 'WPARAM'

Can you please let me know how to proceed?

Thanks
madhavi
ASKER CERTIFIED SOLUTION
Avatar of double_axe
double_axe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial