Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SendMessage

Status
Not open for further replies.

cpfc

Programmer
Aug 4, 2003
23
GB
Hi, I want to be able to send a pointer pointing to the following struct:

Code:
struct MyStruct
{
	int Number1;
	int Number2;
};

to another applications window.
I've tried the following:

Code:
MyStruct * info=new MyStruct;
info->Number1=100;
info->Number2=200;
::SendMessage(m_hTargetWindow,WM_APP+1,0,(LPARAM)info);
delete info;

The other application receives the message ok, but the pointer seems to be corrupted, heres an example for the other application:

Code:
void CMainWindow::OnReceiveInfo(WPARAM wParam, LPARAM lParam)
{
	MyStruct * info=(MyStruct*)lParam;
	if (info->Number1==100) AfxMessageBox("here");
}

Once you try calling info->Number1 the application freezes.
Hope that makes sence and help would be appricated, thanks in advance...
 
"The other application receives the message ok"

If you mean by other application an other process, there is your problem. In 32 bit, a pointer in process A is NOT valid in an other process. This differs from the 16 bit environment.
If you want to share data between two processes, there are several ways to do that. Look in MSDN Library for File Mapping, WM_COPYDATA, named pipes, sockets, and all those others i forgot.


Marcel
 
hmmm thanks I'll look into it...
 
THe easiest method for data transmission between processes are files. Other methods are pipes, TCP/Unix sockets, RPC/COM/CORBA.

Ion Filipski
1c.bmp
 
also, because you are deleting your data immediately afterwards, the pointer will contain random data

MyStruct * info=new MyStruct;
info->Number1=100;
info->Number2=200;
::SendMessage(m_hTargetWindow,WM_APP+1,0,(LPARAM)info);
delete info;

Skute

"There are 10 types of people in this World, those that understand binary, and those that don't!"
 
Anyway, data will not be passed to other process, you could delete pointer or not, is not difference in this case.

Ion Filipski
1c.bmp
 
Even if it was the same process, SendMessage won't return until the message as been totaly handled, therefor calling delete after calling SendMessage won't matter.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top