用PostMessage或SendMessage发送结构体指针

SendMessage可以随意发送结构体指针。
PostMessage则必须注意结构体的生命周期。

例如如下发送代码,使用PostMessage:

    struct _tag_aa
    {
        CString s1;
        char szBuffer[512];
        int a;
        char* szText;
    };
 
    _tag_aa *a=new _tag_aa;
    a->s1="ssssss11111111111111";
    strcpy(a->szBuffer,"Bufferrrrrrrrrrrrrrrrr");
    a->szText="textttttt";
    a->a=120;
 
    PostMessage(WM_UpdateTEXT,(WPARAM)a,0);

接收消息的代码:

    _tag_aa * pA=(_tag_aa*)wParam;
    delete pA;

你可能感兴趣的:(struct,delete)