質問

In my worker thread I create a message that I send to my main dialog. Once the main dialog receives the message and goes into my OnStatusUpdate() function I would like to extract the message from LPARAM lParam and display it in the dialogs edit box. Instead of getting my message all I get is garbage.

UINT CGDC74xDlg::LeakTstThread( LPVOID pParam )
{
    HWND *phObjectHandle = static_cast<HWND *>(pParam);
    CString strTmp = "It works!";
    CString * message = new CString(strTmp);
    ::PostMessage(*phObjectHandle, WM_LEAK_TEST_THREAD, 0, (LPARAM)message);
    ::Sleep(5000);
    delete phObjectHandle;
    return( 0 );
}

LRESULT CGDC74xDlg::OnStatusUpdate(WPARAM wParam, LPARAM lParam)
{
    LPTSTR lpMessage = (LPTSTR)lParam;
    CString s = lpMessage;
    delete lpMessage;
    GetDlgItem(IDC_EDIT_LEAK_TEST_RESULTS)->SetWindowText(s);
    return 0;
}
役に立ちましたか?

解決

In your case, LPARAM does not contain a CString. It contains a pointer to a CString.

So you would obtain it like this:

CString *message = (CString*)lParam;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top