描述:
我用vc++6建立一个名为prog的MFC程序,然后加入一个DAQAI的控件,在类视图中自动产生了一个名为CDAQAI的类(daqai.h daqai.cpp),然后在CprogView的头文件中加入#include "daqai.h" 并且添加CDAQAI m_DaqAi成员变量,添加OnCreate消息映射函数,然后在OnCreate中用m_DaqAi.Create(NULl,WS_VISIBLE,CRect(0,0,22,22),this,2000)动态创建控件,编译没有问题,但是运行(debug)时提示
Debug Assertion Failed!
Program: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.exe
File: occsite.cpp
Line: XXXX
于是我做了个副本转到vs2003中编译、运行完全正常,于是跟踪了一下:
CDAQAI是公有继承了CWnd的
并且重载了许函数Create
virtual BOOL CAQAI::Create(LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID,
CFile* pPersist = NULL, BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL)
{
return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
pPersist, bStorage, bstrLicKey);
}
GetClsid() 返回控件的class id,CreateControl是CWnd的成员函数,在return后面的函数应该调用CWnd::CreateControl(...)
***
***
结果在VC6中直接调用COleControlSite::CreateControl(.....),而不是先调用CWnd::CreateControl(...)
HRESULT COleControlSite::CreateControl(CWnd* pWndCtrl, REFCLSID clsid,
LPCTSTR lpszWindowName, DWORD dwStyle, const POINT* ppt, const SIZE* psize,
UINT nID, CFile* pPersist, BOOL bStorage, BSTR bstrLicKey)
{... ...}
导致函数调用的第一个参数FetClsid()返回的参数传到了COleControlSite::CreateControl中的pWndCtrl中,而第二个参数WS_VISIBLE传到了COleControlSite::CreateControl的clsid中,运行出错。
***
***
在vs2003种却是先调用了CWnd::CreateControl
BOOL CWnd::CreateControl( REFCLSID clsid, LPCTSTR lpszWindowName,
DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID,
CFile* pPersist, BOOL bStorage, BSTR bstrLicKey )
{
//略
return( CreateControl( clsid, lpszWindowName, dwStyle, &pt, &size,
pParentWnd, nID, pPersist, bStorage, bstrLicKey ) );
}
然后return后面的函数调用
BOOL CWnd::CreateControl(REFCLSID clsid, LPCTSTR lpszWindowName, DWORD dwStyle,
const POINT* ppt, const SIZE* psize, CWnd* pParentWnd, UINT nID,
CFile* pPersist, BOOL bStorage, BSTR bstrLicKey)
{
//略
return pParentWnd->m_pCtrlCont->CreateControl(this, clsid, lpszWindowName,
dwStyle, ppt, psize, nID, pPersist, bStorage, bstrLicKey);
}
return 后面的函数调用
BOOL COleControlContainer::CreateControl(CWnd* pWndCtrl, REFCLSID clsid,
LPCTSTR lpszWindowName, DWORD dwStyle, const POINT* ppt, const SIZE* psize,
UINT nID, CFile* pPersist, BOOL bStorage, BSTR bstrLicKey,
COleControlSite** ppNewSite){... ...}
参数完全匹配,所以也没有问题
哪位高人能指点一下,现在这个情况怎么解决啊,为什么VC6中不是先调用CWnd::CreateControl,难道要在什么地方要设置一下?
急啊……