我有一个动态链接库,里面用sendmessage发送个结构体给VC6.0 win32应用程序,我在消息循环那里可以获得系统消息WM_COPYDATA,但是不知道怎么取得sendmessage发送的结构体。大侠们帮我下吧,我是新手!

解决方案 »

  1.   

     // (defined in WINUSER.H)
    struct COPYDATASTRUCT {
       DWORD dwData;     // whatever you want
       DWORD cbData;     // length of data
       PVOID lpData;     // ptr to data
    };
    COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)lParam;
    const char* lpText = (const char*)pcds->lpData;
    DWORD len = pcds->cbData;
    //m_file.Write(lpText, len);
      

  2.   

    LRESULT SendMessage(
      HWND hWnd,      // handle to destination window
      UINT Msg,       // message
      WPARAM wParam,  // first message parameter
      LPARAM lParam   // second message parameter
    );
    你将struct作为wParam或lParam传过去,在那边直接Msg.wParam或Msg.lParam就可以取到了啊
      

  3.   

    WM_COPYDATA是个特殊消息(跨进程),系统为他分配全局内存的,不是指针的问题
      

  4.   

    WM_COPYDATA Message--------------------------------------------------------------------------------An application sends the WM_COPYDATA message to pass data to another application. Syntax
    To send this message, call the SendMessage function as follows. 
    lResult = SendMessage(      // returns LRESULT in lResult     (HWND) hWndControl,      // handle to destination control     (UINT) WM_COPYDATA,      // message ID     (WPARAM) wParam,      // = (WPARAM) () wParam;    (LPARAM) lParam      // = (LPARAM) () lParam; );   
    ParameterswParam
    Handle to the window passing the data. 
    lParam
    Pointer to a COPYDATASTRUCT structure that contains the data to be passed. 
    Return ValueIf the receiving application processes this message, it should return TRUE; otherwise, it should return FALSE. 
    ResThe data being passed must not contain pointers or other references to objects not accessible to the application receiving the data. While this message is being sent, the referenced data must not be changed by another thread of the sending process. The receiving application should consider the data read-only. The lParam parameter is valid only during the processing of the message. The receiving application should not free the memory referenced by lParam. If the receiving application must access the data after SendMessage returns, it must copy the data into a local buffer. 
      

  5.   

    http://book.csdn.net/bookfiles/212/10021210209.shtml
      

  6.   

    我想问的是在win32应用程序里如何实现,不是mfc中。mfc中可以自动生成WM_COPYDATA的消息响应函数, 但是在win32 application我不知道怎样实现。我的QQ是331207592,可以的请加我!
      

  7.   

    "我在消息循环那里可以获得系统消息WM_COPYDATA"那么:
    COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)lParam;
    const char* lpText = (const char*)pcds->lpData;
    DWORD len = pcds->cbData;
    //m_file.Write(lpText, len);
      

  8.   

    switch (message) 
    {
    case WM_COMMAND:
    wmId    = LOWORD(wParam); 
    wmEvent = HIWORD(wParam); 
    // Parse the menu selections:
    switch (wmId)
    {
    case IDM_ABOUT:
    typedef int(* lpsFun)(DWORD,HWND);
    HINSTANCE hdll;
    lpsFun InstallHOOK;
    hdll = LoadLibrary("Hdll.dll");
    if(hdll != NULL)
    {
    InstallHOOK = (lpsFun)GetProcAddress(hdll,"InstallHOOK");
    if(InstallHOOK !=NULL)
    {
    InstallHOOK(3723,hWnd);
    }
    }
                FreeLibrary(hdll);
       break;
    case IDM_EXIT:
       DestroyWindow(hWnd);
       break;
    default:
       return DefWindowProc(hWnd, message, wParam, lParam);
    }
    break;
    case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    // TODO: Add any drawing code here...
    RECT rt;
    GetClientRect(hWnd, &rt);
    DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
    EndPaint(hWnd, &ps);
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    case WM_COPYDATA:(在这里可以收到WM_COPYDATA,但是我动态链接库里发过来的结构体,我就不知道怎么接收了)
                             ~~~~~~~~
                            break;
      

  9.   

    1>.COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)lParam;
    2>.dll中如何把结构放在这里?const YourStr* lpYourStr = (const YourStr*)pcds->lpData;
    3>.长度应该等于sizeof(YourStr),DWORD len = pcds->cbData;
      

  10.   

    如果不是跨进程,可以按2楼:
    “你将struct作为wParam或lParam传过去,在那边直接Msg.wParam或Msg.lParam就可以取到了啊”
      

  11.   

    case WM_COPYDATA:
    PCOPYDATASTRUCT data; 
    data=(PCOPYDATASTRUCT)lParam;
    if (data->dwData==TYPE_RegCreateKeyExA)
    {
    MessageBox(NULL,"dwdata成功!","ccc",MB_OK);
    }
    PARAMS* params = (PARAMS*)data->lpData;(这一句存在错误,error C2361: initialization of 'params' is skipped by 'default' label)
      

  12.   

    这个错误是因为:
    PARAMS* params 
    定义的地方不对。2个办法:
    1>把定义移到switch前。
    2>把case用{}括起来。