开发者社区> 问答> 正文

MFC Dialog报错问题,m_hWnd为空 <b> ?报错

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

错误信息如图

展开
收起
爱吃鱼的程序员 2020-06-23 14:34:15 798 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

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

    CVSOConnectorDlgdlg;dlg.DoModal()

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

    有的,
    CVSOConnectorDlg*dlg=newCVSOConnectorDlg;
    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){deletepShellManager;}returndlg->Create(IDD_VSOCONNECTOR_DIALOG);

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

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

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

    classCVSOConnectorDlg:publicCDialogEx
    {
    //Construction
    public:
    CVSOConnectorDlg(CWnd*pParent=NULL);//standardconstructor
    ~CVSOConnectorDlg();
    //DialogData
    enum{IDD=IDD_VSOCONNECTOR_DIALOG};

    protected:virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport

    //Implementation
    protected:
    HICONm_hIcon;

    //GeneratedmessagemapfunctionsvirtualBOOLOnInitDialog();afx_msgvoidOnPaint();afx_msgHCURSOROnQueryDragIcon();DECLARE_MESSAGE_MAP()

    public:
    CMstscax1m_VSOConnector;
    ServerDetailsserverdetails;
    afx_msgvoidOnBnClickedButton1();
    INT_PTRDoModal();
    DECLARE_EVENTSINK_MAP()
    voidOnDisconnectedMstscax1(longdiscReason);
    voidOnConnectedMstscax1();
    //afx_msgvoidOnSize(UINTnType,intcx,intcy);

    public:
    CProgressBarpb;
    voidOnConnectingMstscax1();
    voidOnLogonErrorMstscax1(longlError);
    afx_msgvoidOnSize(UINTnType,intcx,intcy);
    CRectm_rect;
    //afx_msgvoidOnNcPaint();
    afx_msgvoidOnKillFocus(CWnd
    pNewWnd);
    afx_msgintOnMouseActivate(CWnd*pDesktopWnd,UINTnHitTest,UINTmessage);
    voidOnRemoteProgramResultMstscax1(LPCTSTRbstrRemoteProgram,longlError,BOOLvbIsExecutable);
    voidOnRemoteProgramDisplayedMstscax1(BOOLvbDisplayed,unsignedlonguDisplayInformation);
    voidOnIdleTimeoutNotificationMstscax1();
    voidOnConfirmCloseMstscax1(BOOL*pfAllowClose);
    voidOnWarningMstscax1(longwarningCode);
    voidOnRequestContainerMinimizeMstscax1();
    afx_msgvoidOnClose();
    voidOnEnterFullScreenModeMstscax1();
    voidOnLeaveFullScreenModeMstscax1();
    voidOnRequestGoFullScreenMstscax1();
    voidOnRequestLeaveFullScreenMstscax1();
    voidOnRemoteDesktopSizeChangeMstscax1(longwidth,longheight);
    };

    2020-06-23 14:34:31
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载