2 hopedream2008 hopedream2008 于 2015.07.23 14:24 提问

MFC Dialog报错问题,m_hWnd为空 5C
mfc

代码如下:
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;

错误信息如图

7个回答

oyljerry
oyljerry   Ds   Rxr 2015.07.23 14:32

你创建变量还要DoModal才会真正生成对话框

 CVSOConnectorDlg dlg;
dlg.DoModal()
hopedream2008
hopedream2008 create和DoModal一样吧
2 年多之前 回复
hopedream2008
hopedream2008 在后面的代码有做,
2 年多之前 回复
caozhy
caozhy   Ds   Rxr 2015.07.23 14:54

CVSOConnectorDlg dlg;
dlg.Create(对话框资源id);

hopedream2008
hopedream2008 有做的,就是在CVSOConnectorDlg dlg;直接崩溃
2 年多之前 回复
hopedream2008
hopedream2008   2015.07.23 15:34

有的,
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);
hopedream2008
hopedream2008 回复oyljerry: ralease是没问题,debug也要解呀,还有就是我的程序里面用到一个ActiveX控件
2 年多之前 回复
hopedream2008
hopedream2008 回复oyljerry: ralease是没问题,debug也要解呀,还有就是我的程序里面用到一个ActiveX控件
2 年多之前 回复
oyljerry
oyljerry 代码上看,没什么问题,估计更大可能性是Debug时有问题,VC有一些Debug宏检查不太正确,可以先用release版本运行
2 年多之前 回复
caozhy
caozhy   Ds   Rxr 2015.07.23 15:38

m_hWnd还是m_pMainWnd为空?
m_pMainWnd是什么类型

hopedream2008
hopedream2008 你能加下我的QQ吗,我这上传不了图片414666778,谢谢
2 年多之前 回复
hopedream2008
hopedream2008 ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));断点指向这里,m_pMainWnd是CWnd*
2 年多之前 回复
VisualEleven
VisualEleven   Ds   Rxr 2015.07.25 09:14

要看一下CVSOConnectorDlg类的构造函数中写了什么

hopedream2008
hopedream2008 构造函数里面就是一些变量和函数的定义
2 年多之前 回复
notfindjob
notfindjob   2015.07.25 15:53

将dlg换成CVSOConnectorDlg*,或者全局变量。
编译器bug!!!

hopedream2008
hopedream2008 有试过,指针和全局变量,
2 年多之前 回复
hopedream2008
hopedream2008   2015.07.27 08:18

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);
};

Csdn user default icon
上传中...
上传图片
插入图片