框架字自动生成的mdi程序。在属性窗口ComboBox选这一个下拉项目时,下面函数收到消息。在这个函数里面调用AfxMessageBox(_T("test"))出错。
如果只是改变TextBox的数据,不会出错,MessageBox正常显示。LRESULT CPropertiesWnd::OnPropertyChanged (WPARAM wpAram,LPARAM lParam)
{
UINT uID = (UINT)wpAram;
AfxMessageBox(_T("test"));  //调用这个函数出错。
return 0;
}试来试去,发现和编译环境有关。1, 在共享DLL中使用MFC,使用unicode字符集//这个库文件afxtls.cpp
// special version of CThreadSlotData::GetData that only works with
// thread local storage (and not process local storage)
// this version is inlined and simplified for speed
inline void* CThreadSlotData::GetThreadValue(int nSlot)
{
EnterCriticalSection(&m_sect);
ASSERT(nSlot != 0 && nSlot < m_nMax);
ASSERT(m_pSlotData != NULL);
ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED);
ASSERT(m_tlsIndex != (DWORD)-1);
if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds.
{
LeaveCriticalSection(&m_sect);
return NULL;
} CThreadData* pData = (CThreadData*)TlsGetValue(m_tlsIndex);
if (pData == NULL || nSlot >= pData->nCount)
{
LeaveCriticalSection(&m_sect);
return NULL;
}
void* pRetVal = pData->pData[nSlot];
LeaveCriticalSection(&m_sect);
return pRetVal;  //vs在这里断下。
}
2, 字符集:未设置; 不管是共享DLL使用MFC还是静态库MFC。 都在同一个地方报错。
//这个库文件wincore.cpp
/////////////////////////////////////////////////////////////////////////////
// Default CWnd implementationLRESULT CWnd::DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
{
if (m_pfnSuper != NULL)
return ::CallWindowProc(m_pfnSuper, m_hWnd, nMsg, wParam, lParam);  //vs在这里断下。 WNDPROC pfnWndProc;
if ((pfnWndProc = *GetSuperWndProcAddr()) == NULL)
return ::DefWindowProc(m_hWnd, nMsg, wParam, lParam);
else
return ::CallWindowProc(pfnWndProc, m_hWnd, nMsg, wParam, lParam);
}
3, 静态库中使用MFC,使用unicode字符集。这个正常。
   如果非用unicode每碰到一个字符串就要输入 _T(...) ,好烦琐啊。

解决方案 »

  1.   

    我是求助啊。不得其解。只好继续尝试。 共享DLL的MFC + unicode 好象又不错了。CMFCPropertyGridCtrl通过SendMessage(AFX_WM_PROPERTY_CHANGED, GetDlgCtrlID(), LPARAM(pProp))发送消息。解决方法有2个:
    1,重载CMFCPropertyGridProperty::OnUpdateValue(),避免调用CMFCPropertyGridCtrl::OnPropertyChanged发送AFX_WM_PROPERTY_CHANGED给主窗口,通过其他方式交给主窗口。2,OnPropertyChanged收到消息之后,不要处理,用PostMessage转发给其他窗口处理。
       除非另有线程偷偷改变属性窗口的项,否则PosMessage接收到的CMFCPropertyGridProperty指针还是有效的。