我现在VC的工程是个Win32 Console Application,由于要调用EXCEL2000,想使用MFC中的方法。我在项目设置中选择了[Use MFC in a Static Library],由于在[View]->[ClassWizard]中无法添加EXCEL9.OLB,于是我将生成好的excel9.cpp、excel9.h添加到工程中,编译有好多错误。请各位老大帮忙指点一下,有什么方法,能让我在已建好的Win32 Console Application工程中使用MFC的方法调用EXCEL。

解决方案 »

  1.   

    创建ConsoleApplication的时候第二步,第四个选项就是支持MFC的
      

  2.   

    在创建Win32 Console Application工程的时候
    选择An Application that supports MFC
      

  3.   

    在stdafx.h中#include <afxwin.h>
      

  4.   

    TO  flyelf(空谷清音):
    添加后出错,请问是什么原因?
    内容如下:
    =================================================================================
    Compiling...
    stdafx.cpp
    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>
    Error executing cl.exe.
    Creating browse info file...
    ==================================================================================
      

  5.   

    错误就是你用了
    #include <windows.h>
    加入下面两个头文件就可以支持MFC了,不过不是通过新工程创建出来的,还有很多地方要手工改比如多线程支持什么的#include <afxwin.h>         // MFC core and standard components
    #include <afxcmn.h> // MFC support for Windows Common Controls
      

  6.   

    怎样在SDK程序中使用MFC中的辅助类
      
        由于MFC中的辅助类,如CFileDialog,CFileFind,CString等使用起来非常的方便如果用API来完成相应的工作,则需要自己完成大量的重复工作,使用MFC的辅助类可以节省大量的开发时间,具体方法如下:1.加入相应的头文件    由于在SDK程序中一定要包含windows.h头文件,所以在使用MFC中的类时,如加入afx.h一类的头文件会有一个提示与windows.h相冲突,解决的办法是,去掉windows.h,然后在所有的.h文件前加入#include "stdafx.h"#define VC_EXTRALEAN    // Exclude rarely-used stuff from Windows headers
    #include <afxwin.h>        // MFC core and standard components
    #include <afxext.h>        // MFC extensions
    #include <afxdisp.h>        // MFC Automation classes
    #include <afxdtctl.h>        // MFC support for Internet Explorer 4 Common Controls
    #ifndef _AFX_NO_AFXCMN_SUPPORT
    #include <afxcmn.h>    // MFC support for Windows Common Controls
    #endif // _AFX_NO_AFXCMN_SUPPORT    注意一定要在所有的头文件之前加入这几行,而起顺序最好不要改变,否则会有大量的错误提示。2.更改编译设置    在Project->Setting->General中选Use MFC in a Shared DLL或者Use MFC in static Library,并把project->Setting->C/C++ 中的Use runing-time library 由Single-Threaded改为相应的Multithreaded。
     给你参考一下吧不过这个win32的windows程序的使用方法
    不是console程序的使用,你参考一下吧
      

  7.   

    在SDK程序中,建议直接用API的方式来调用Excel接口,看看MSDN,其实也不难的。
      

  8.   

    TO handsomerun(毛毛):
      谢谢,不过我是在做二次开发,不能去掉windows.h,不然改动太大了,你说的方法我看到过,我用不了,还有别的方法吗?
    TO Mackz(在相互):
      我是看到不少用API调用EXCEL的,但是都很简单,我要实现的是将取得的数据按照模板的样式,生成新的EXCEL文件,你能给我找个例子吗?
      

  9.   

    那你就把
    #include <windows.h>
    这句注释掉,不就行了
      

  10.   

    由于在支持MFC时需要
    #include <afxwin.h>
    这个头文件中已经包含了windows.h
      

  11.   

    TO tfq2002(天涯闲游) :
        老大,不是我不想注掉windows.h,因为我做的是二次开发,我要调基盘,基盘引用的windows.h。
      

  12.   

    TO tfq2002(天涯闲游) :
        老大,不是我不想注掉windows.h,因为我做的是二次开发,我要调基盘,基盘引用的windows.h-----------------------------------------------
    那就在windows.h中include<afxwin.h>
      

  13.   

    谢谢各位,我不能对windows.h进行修改,看来我用不了MFC了,贴子我就先结了,如果谁有API调用EXCEL模板生成EXCEL文件的代码请发给我,我用100分进行交换,谢谢!
    我的信箱是:[email protected]