DLL里是一個對話框。視窗類去呼叫創建它,讓它作為子視窗(呼叫第一張圖片中的函式,引數傳this)。 在create DLL對話框時出斷言,如圖2。 請問高手這問題如何解決。

uj5u.com熱心網友回復:
借用吧友的答案如果你的對話是在動態庫中創建的,應該是動態庫AfxFindResourceHandle的時候沒有加載動態庫的資源,加載的是可執行程式exe的資源。
參考
http://blog.csdn.net/mniwc/article/details/6748379
uj5u.com熱心網友回復:
之前不作為子視窗直接 pDlg->Create(IDD) 不傳父視窗this指標沒問題
傳了this 就斷言了
pDlg->Create(IDD,this)動作在DLL中完成的
uj5u.com熱心網友回復:
我不是很明白,
你這句“如果你的對話是在動態庫中創建的”, 你強調的是動態鏈接還是靜態鏈接嗎
create Dlg是在DLL類中實作的, 只不過父視窗呼叫 create函式 __declspec(dllexport) 時 給他傳遞了父視窗引數指標
參考有點復雜,能否就我這問題簡單解釋下
uj5u.com熱心網友回復:
崩潰的時候在彈出的對話框按相應按鈕進入除錯,按Alt+7鍵查看Call Stack即“呼叫堆疊”里面從上到下列出的對應從里層到外層的函式呼叫歷史。雙擊某一行可將游標定位到此次呼叫的源代碼或匯編指令處,看不懂時雙擊下一行,直到能看懂為止。uj5u.com熱心網友回復:
老師,直到最后也不懂啊!!!
問題在:
void CWnd::AssertValid() const
{
CHandleMap* pMap = afxMapHWND();
ASSERT(pMap != NULL);
}
這張MAP表是空的~~~
我是在
CWnd中 呼叫DLL中的create(IDD)
int CCalculator::OnCreate(LPCREATESTRUCT lpCreateStruct) //父視窗create
{
if (CBasicWnd::OnCreate(lpCreateStruct) == -1)
return -1;
m_Hwd = OpenCalculator(this); //create DLL子視窗 《------傳this 出斷言
return 0;
}
#define DLLEXPORT extern "C" __declspec(dllexport)
DLLEXPORT HWND OpenCalculator(CWnd *wnd);
HWND OpenCalculator(CWnd *wnd)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
pTD->Create(IDD_CALCULATOR_DIALOG,wnd);
HWND hWnd =pTD->GetSafeHwnd();
return hWnd;
}
uj5u.com熱心網友回復:
請檢查每個函式呼叫的回傳值。小心駛得萬年船。
注意分散在各處的相關聯呼叫的先后順序。必要時加鎖/同步等待。
Synchronization Functions
The following functions are used in synchronization.
CancelWaitableTimer
CreateEvent
CreateMutex
CreateSemaphore
CreateWaitableTimer
DeleteCriticalSection
EnterCriticalSection
GetOverlappedResult
InitializeCriticalSection
InitializeCriticalSectionAndSpinCount
InterlockedCompareExchange
InterlockedDecrement
InterlockedExchange
InterlockedExchangeAdd
InterlockedIncrement
LeaveCriticalSection
MsgWaitForMultipleObjects
MsgWaitForMultipleObjectsEx
OpenEvent
OpenMutex
OpenSemaphore
OpenWaitableTimer
PulseEvent
QueueUserAPC
ReleaseMutex
ReleaseSemaphore
ResetEvent
SetCriticalSectionSpinCount
SetEvent
SetWaitableTimer
SignalObjectAndWait
TimerAPCProc
TryEnterCriticalSection
WaitForMultipleObjects
WaitForMultipleObjectsEx
WaitForSingleObject
WaitForSingleObjectEx
《Windows核心編程》
uj5u.com熱心網友回復:
stack 如下,請趙老師結合上一回貼分析下
CWnd::AssertValid() line 890 + 25 bytes
AfxAssertValidObject(const CObject * 0x0044b028 {CCalculator hWnd=0x000108b8}, const char * 0x5f4d1330 THIS_FILE, int 258) line 108
CWnd::CreateDlgIndirect(const DLGTEMPLATE * 0x1006e700, CWnd * 0x0044b028 {CCalculator hWnd=0x000108b8}, HINSTANCE__ * 0x10000000) line 260
CDialog::CreateIndirect(const DLGTEMPLATE * 0x1006e700, CWnd * 0x0044b028 {CCalculator hWnd=0x000108b8}, void * 0x00000000, HINSTANCE__ * 0x10000000) line 223
CDialog::CreateIndirect(void * 0x1006e700, CWnd * 0x0044b028 {CCalculator hWnd=0x000108b8}, HINSTANCE__ * 0x10000000) line 200 + 22 bytes
CDialog::Create(const char * 0x00000066, CWnd * 0x0044b028 {CCalculator hWnd=0x000108b8}) line 182 + 20 bytes
CDialog::Create(unsigned int 102, CWnd * 0x0044b028 {CCalculator hWnd=0x000108b8}) line 543 + 29 bytes
OpenCalculator(CWnd * 0x0044b028 {CCalculator hWnd=0x000108b8}) line 73
CCalculator::OnCreate(tagCREATESTRUCTA * 0x0012ec68) line 40 + 9 bytes
CWnd::OnWndMsg(unsigned int 1, unsigned int 0, long 1240168, long * 0x0012ea44) line 1822 + 13 bytes
CWnd::WindowProc(unsigned int 1, unsigned int 0, long 1240168) line 1596 + 30 bytes
AfxCallWndProc(CWnd * 0x0044b028 {CCalculator hWnd=0x000108b8}, HWND__ * 0x000108b8, unsigned int 1, unsigned int 0, long 1240168) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x000108b8, unsigned int 1, unsigned int 0, long 1240168) line 379
AfxWndProcBase(HWND__ * 0x000108b8, unsigned int 1, unsigned int 0, long 1240168) line 220 + 21 bytes
uj5u.com熱心網友回復:
CHandleMap* PASCAL afxMapHWND(BOOL bCreate)
{
AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
if (pState->m_pmapHWND == NULL && bCreate)
{
BOOL bEnable = AfxEnableMemoryTracking(FALSE);
#ifndef _AFX_PORTABLE
_PNH pnhOldHandler = AfxSetNewHandler(&AfxCriticalNewHandler);
#endif
pState->m_pmapHWND = new CHandleMap(RUNTIME_CLASS(CTempWnd),
offsetof(CWnd, m_hWnd));
#ifndef _AFX_PORTABLE
AfxSetNewHandler(pnhOldHandler);
#endif
AfxEnableMemoryTracking(bEnable);
}
return pState->m_pmapHWND;
}
pState->m_pmapHWND 的值是NULL
引數bcreate 是 0 (默認是0 ??)
AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
這個函式怎么看,
大神來解釋下吧
uj5u.com熱心網友回復:
https://www.baidu.com/s?wd=AfxGetModuleThreadState
uj5u.com熱心網友回復:
把DLL 對話框 中的 DoDataExchange 函式 中的 代碼都屏蔽掉試試看uj5u.com熱心網友回復:
這里面有關聯的控制元件變數啊,怎么刪啊? DDX_Control 等
uj5u.com熱心網友回復:
dll呼叫介面一開始加上這句AFX_MANAGE_STATE(AfxGetStaticModuleState());
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/109625.html
標籤:基礎類
下一篇:VC/MFC 中使用水晶報表
