problems allocating memory for structs
hello !
i have a struct and i want to send this with
sendmessage to another application.
this application should extract the struct
and go on with the data.
but it doesn´t work. maybe it´s something wrong
with the allocation of memory for the struct.
but i have no experience in doing that.
thanks for help,
ralph
/////////////////////////////////////////////
typedef struct
{
int number;
char Name[20];
char Lastname[30];
} Student;
/////////////////////////////////////////////
// function, application 1
.
.
.
Student *pData = new Student;
pData->number = 12;
memcpy (pData->Name,m_Name,Name_Length);
memcpy (pData->Name+Name_Length,"\0",1);
memcpy (pData->Lastname,m_Lastname,Lastname_Length);
memcpy (pData->Lastname+Lastname_Length,"\0",1);
COPYDATASTRUCT pCopyDataStruct;
pCopyDataStruct.dwData = 0;
pCopyDataStruct.cbData = 0;
pCopyDataStruct.lpData = (void*)pData;
LRESULT res = ::SendMessage(Hwnd_Target,WM_COPYDATA,NULL,(LPARAM)&pCopyDataStruct);
/////////////////////////////////////////////
// function, application 2
LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_COPYDATA: COPYDATASTRUCT *pCopyDataStruct = (COPYDATASTRUCT *) lParam;
Student *pData = new Student;
pData = (Student*)pCopyDataStruct->lpData;
if (pData->number == 12)
{
// use pData->Name;
// use pData->Lastname;
}
break;
}
}
/////////////////////////////////////////////
Re: problems allocating memory for structs
You can't share objects between applications, because the adress of your object is not absolute through the system, but relative to your app. You should use shared memory between your apps
Look at http://www.microsoft.com/MSJ/1198/WI...ked1198top.htm
HTH.
K.