CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 1999
    Location
    Hamburg, Germany
    Posts
    79

    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;
    }
    }

    /////////////////////////////////////////////



  2. #2
    Join Date
    May 1999
    Location
    Toulouse, France
    Posts
    171

    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.

    We're talking ****, 'cause life is a 'biz
    You know it is
    Everybody tryin' to get rich
    God ****!
    All I wanna do is live !

    KoRn, Children of the Korn

  3. #3
    Join Date
    Sep 1999
    Posts
    9

    different memory space!

    every application have own memory space on windows platform and the space was private.

    a application can't to access anthor application's
    memory space.

    you need using FileMapping to solution the question.


    -----------My Signature-----------
    Hi,everybody
    I am Sound_Wang from P.R.China.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured