问题描述
- MFC Dialog报错问题,m_hWnd为空
-
代码如下:
BOOL CVSOConnectorApp::InitInstance()
{
//m_pMainWnd = (CWnd*)malloc(sizeof(m_pMainWnd));
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); char buf[MAXBUFSIZE + 1]; char value[MAXPARAMETERLEN + 1]; CVSOConnectorDlg dlg;//报错地方,debug模式下只要执行到这就会报错,release下是ok的 m_pMainWnd = &dlg; 错误信息如图
解决方案
你创建变量还要DoModal才会真正生成对话框
CVSOConnectorDlg dlg;
dlg.DoModal()
解决方案二:
CVSOConnectorDlg dlg;
dlg.Create(对话框资源id);
解决方案三:
有的,
CVSOConnectorDlg *dlg = new CVSOConnectorDlg;
m_pMainWnd = dlg;
dlg->serverdetails.setServer(sd.getServer());
dlg->serverdetails.setPort(sd.getPort());
dlg->serverdetails.setUsername(sd.getUsername());
dlg->serverdetails.setPassword(sd.getPassword());
dlg->serverdetails.setDomain(sd.getDomain());
dlg->serverdetails.setGatewayHostname(sd.getGatewayHostname());
dlg->serverdetails.setFullScreen(true);
if (pShellManager != NULL)
{
delete pShellManager;
}
return dlg->Create(IDD_VSOCONNECTOR_DIALOG);
解决方案四:
m_hWnd还是m_pMainWnd为空?
m_pMainWnd是什么类型
解决方案五:
要看一下CVSOConnectorDlg类的构造函数中写了什么
解决方案六:
将dlg换成CVSOConnectorDlg*,或者全局变量。
编译器bug!!!
解决方案七:
class CVSOConnectorDlg : public CDialogEx
{
// Construction
public:
CVSOConnectorDlg(CWnd* pParent = NULL); // standard constructor
~CVSOConnectorDlg();
// Dialog Data
enum { IDD = IDD_VSOCONNECTOR_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
CMstscax1 m_VSOConnector;
ServerDetails serverdetails;
afx_msg void OnBnClickedButton1();
INT_PTR DoModal();
DECLARE_EVENTSINK_MAP()
void OnDisconnectedMstscax1(long discReason);
void OnConnectedMstscax1();
//afx_msg void OnSize(UINT nType, int cx, int cy);
public:
CProgressBar pb;
void OnConnectingMstscax1();
void OnLogonErrorMstscax1(long lError);
afx_msg void OnSize(UINT nType, int cx, int cy);
CRect m_rect;
// afx_msg void OnNcPaint();
afx_msg void OnKillFocus(CWnd pNewWnd);
afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
void OnRemoteProgramResultMstscax1(LPCTSTR bstrRemoteProgram, long lError, BOOL vbIsExecutable);
void OnRemoteProgramDisplayedMstscax1(BOOL vbDisplayed, unsigned long uDisplayInformation);
void OnIdleTimeoutNotificationMstscax1();
void OnConfirmCloseMstscax1(BOOL* pfAllowClose);
void OnWarningMstscax1(long warningCode);
void OnRequestContainerMinimizeMstscax1();
afx_msg void OnClose();
void OnEnterFullScreenModeMstscax1();
void OnLeaveFullScreenModeMstscax1();
void OnRequestGoFullScreenMstscax1();
void OnRequestLeaveFullScreenMstscax1();
void OnRemoteDesktopSizeChangeMstscax1(long width, long height);
};