Solved

How to send user defined structure using PostMessage?

Posted on 2004-09-13
5
684 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 30 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
has77  challenge 9 98
pre4 challenge 19 111
Line meaning 9 91
Problem to Office 1 45
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.

726 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