我写了一个网关程序,基于对话框的mfc,在我的机器上(vc6.0环境)可以正常跳出主对话框,
但是在一个没有安装vc的机器上。运行程序不能生成主对话框。
根据mfc向导,app类的初始化中生成对话框架,AppLog("1111111111111111111111111111111111111111111111\n")这句可以打印,说明程序进入到app;但是AppLog("nResponse:%d\n",nResponse)这句打印出来的日志显示dlg.DoModal()返回的值为-1(创建对话框失败),
程序不能转入到CMsgProdlg类的OnInitDialog()函数中。BOOL CMsgProApp::InitInstance()
{
AfxEnableControlContainer();
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CMsgProDlg dlg;
m_pMainWnd = &dlg;
AppLog("1111111111111111111111111111111111111111111111\n");
int nResponse = dlg.DoModal();
AppLog("nResponse:%d\n",nResponse);  //打印日志
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
} return TRUE;
}AppLog("nResponse:%d\n",nResponse);

解决方案 »

  1.   

    把项目设置为使用MFC静态库试试。
      

  2.   

    projiect->settings->general下面microsoft foundation classes下面设成use mfc in static libaray编译后,release版本报错,debug没有问题,另外我的程序用到了第三方开发包,不知道是不是因为用了第三方开发包的库文件,所以release版本报错。
    部分错误如下:
    afxcw.lib(filecore.obj) : error LNK2001: unresolved external symbol __mbsinc
    nafxcw.lib(dlgfile.obj) : error LNK2001: unresolved external symbol __mbsinc
    nafxcw.lib(dbcore.obj) : error LNK2001: unresolved external symbol __mbsinc
      

  3.   

    release版也要设置成use mfc in static libaray
      

  4.   

    把Release版本的项目属性配置成和Debug版本一样,重新编译
      

  5.   

    release和debug都是静态库编译的,但是release编译不过。
    我开发的是网关程序,用到的是第三方api函数库。这个也不属于控件吧。
    不能创建的主对话框用到了数字静态控件(类似时钟、旅程表),但是它不是以库的形式导入的,是源代码的形式加入到工程中,应该是直接用就可以。
    下面就是这个数字控件类的定义:
    class CDigitST : public CStatic
    {
    public:
    CDigitST();
    virtual ~CDigitST();
        enum { ST_LEFT = 0x01, 
    ST_TOP = 0x02,
    ST_RIGHT = 0x04,
    ST_BOTTOM = 0x08};public: // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CDigitST)
    //}}AFX_VIRTUALpublic:
    BOOL SetStyle(UINT nBitmapId, int nPrecision); void SetValue(int nValue, BOOL bRepaint = TRUE);
    int GetValue(); void SetPrecision(int nPrecision, BOOL bResize = TRUE);
    int GetPrecision(); void SetResize(DWORD dwResize, BOOL bResize = TRUE);
    DWORD GetResize(); void SetZeroPadding(BOOL bPad = FALSE, BOOL bRepaint = TRUE);
    BOOL GetZeroPadding(); void Inc(BOOL bRepaint = TRUE);
    void Dec(BOOL bRepaint = TRUE); static const char* GetVersionC();
    static const short GetVersionI();protected:
    //{{AFX_MSG(CDigitST)
    afx_msg void OnPaint();
    //}}AFX_MSG DECLARE_MESSAGE_MAP()
    private:
    void Resize();
    void PrepareString(char* szDest);
    void DrawDigits(CDC* pDC); CBitmap m_bmDigit;
    int m_nWidth;
    int m_nHeight; int m_nPrecision;
    int m_nValue; BOOL m_bZeroPadding;
    DWORD m_dwResize;
    };
      

  6.   

    afxcw.lib、nafxcw.lib、nafxcw.lib在Release工程设置Link->input->Ignore libraries里忽略试试