如何在非MFC程式中使用MFC類——解決#error : WINDOWS.H already included.

來源:互聯網
上載者:User

   我想在WinProc函數中使用CFileDialog類,於是#include <afxdlgs.h>以後編譯,出現了以下錯誤:

   c:/program files/microsoft visual studio/vc98/mfc/include/afxv_w32.h(14) : fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>

 

   於是, 我在VC6.0Integration Environment中的功能表項目project下的setting中設定使用MFC例"use mfc in a shared DLL"

   即:

       project->setting->general->Microsoft Foundation Classed: 選擇 Use MFC in a shared DLL"

 

   同時,加入:

   #include <afxwin.h>//使用MFC
   #include "afxdlgs.h"//使用CFileDialog類需要包含它

 

  #include "cv.h"
  #include "cxcore.h"
  #include "highgui.h"
  #include "stdafx.h"
  #include "resource.h"
  #include "commdlg.h"
  #include "direct.h"
  #include "stdio.h"
  #include "LbqSVM1.h"
  #include "HogOfImage.h"
  #include "Winbase.h"

 

  #include <afxwin.h>
  #include "afxdlgs.h"

 

  後編譯錯誤依然存在,於是把順序調換一下:

 

 #include <afxwin.h>
 #include "afxdlgs.h"

 #include "cv.h"
 #include "cxcore.h"
 #include "highgui.h"
 #include "stdafx.h"
 #include "resource.h"
 #include "commdlg.h"
 #include "direct.h"
 #include "stdio.h"
 #include "LbqSVM1.h"
 #include "HogOfImage.h"
 #include "Winbase.h"

 

 編譯通過!

 

 學會兩點:

 1、在project->setting->general->Microsoft Foundation Classed: 選擇 Use MFC in a shared DLL

 2、#include 順序調換可能會解決問題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.