[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to send user defined structure using PostMessage?

Posted on 2004-09-13
5
Medium Priority
?
739 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

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 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