?
Solved

How to send user defined structure using PostMessage?

Posted on 2004-09-13
5
Medium Priority
?
716 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:j_madhavi
[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
5 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 12051192
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
0
 

Author Comment

by:j_madhavi
ID: 12051958
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
0
 
LVL 3

Accepted Solution

by:
double_axe earned 120 total points
ID: 12053001
Hi
1. PostMessage returns immediately after call. And variables on a stack can be destroyed when message reach the client. So you should create your variables on a heap:
LOG_VIEW_DATA *info_data;
info_data = new LOG_VIEW_DATA;
PostMessage(WM_MYMSG, (WPARAM)info_data,NULL);
and in the reciever
info_data = (LOG_VIEW_DATA*)wParam;
....
delete info_data;
2. This method will not work between different processes. For different processes you have to call ::SendMessage(WM_COPYDATA,.....);
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

800 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