|
-
September 22nd, 1999, 03:59 AM
#1
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;
}
}
/////////////////////////////////////////////
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|