我在做一个练习的时候遇到一个问题,使用一个 .dll,在 stdafx.h 里面加入如下代码,希望高手指点指点:
#import "C:\Program Files\Common Files\SYSTEM\ADO\msado15.dll" no_namespace \
rename("EOF","EndOfFile")\
rename("LockTypeEnum","newLockTypeEnum")\
rename("DataTypeEnum","newDataTypeEnum")\
rename("FieldAttributeEnum","newFieldAttributeEnum")\
rename("EditModeEnum","newEditModeEnum")\
rename("RecordStatusEnum","newRecordStatusEnum")\
rename("ParameterDirectionEnum","newParameterDirectionEnum")在应用程序类所在的头文件里面加入 变量和 函数的生明,如下:
public:
_RecordsetPtr m_pADOSet;
// int m_iLoginCount;
CString m_sCurrentUser;
CHotel_MISApp();
private:
bool ADOExecute(_RecordsetPtr &ADOSet,_variant_t &strSQL);
_ConnectionPtr ADOConn;
编译后出现如下错误提示。我不明白,不知道是否还要加 什么头文件什么的东西。
Compiling...
StdAfx.cpp
g:\hotel_mis\hotel_mis.h(25) : error C2146: syntax error : missing ';' before identifier 'm_pADOSet'
g:\hotel_mis\hotel_mis.h(25) : error C2501: '_RecordsetPtr' : missing storage-class or type specifiers
g:\hotel_mis\hotel_mis.h(25) : error C2501: 'm_pADOSet' : missing storage-class or type specifiers
g:\hotel_mis\hotel_mis.h(46) : error C2061: syntax error : identifier '_RecordsetPtr'
g:\hotel_mis\hotel_mis.h(47) : error C2146: syntax error : missing ';' before identifier 'ADOConn'
g:\hotel_mis\hotel_mis.h(47) : error C2501: '_ConnectionPtr' : missing storage-class or type specifiers
g:\hotel_mis\hotel_mis.h(47) : error C2501: 'ADOConn' : missing storage-class or type specifiers
Error executing cl.exe.
很急。!!!在先等待,!!

解决方案 »

  1.   

    你hotel_mis.h中并未包含stdafx.h,只有hotel_mis.cpp包含了,所以在hotel_mis.cpp中声明这些变量不会出错。试试hotel_mis.h中#include "stdafx.h"
      

  2.   

    我在hotel-mis.h 里面加了 #include "stdafx.h"的,还是不行。
    在hotel-mis.h 里面有两句向导自动加入的语句,#ifndef __AFXWIN_H__
    #error include 'stdafx.h' before including this file for PCH
    #endif
     那位能解释一下是什么意思?
      

  3.   

    #ifndef __AFXWIN_H__
    #error include 'stdafx.h' before including this file for PCH
    #endif这句话的意思是,如果你没有定义 __AFXWIN_H__ ,编译器就会在你的output窗口内出现
    include 'stdafx.h' before including this file for PCH
    这行错误提示
      

  4.   

    aprilsnow(四月飞雪)☆(莹莹,看,我们的天狼星!)
        
         PCH 是啥子文件哟?
         我那个错误又回因为什么引起的呢?
      

  5.   

    分足够了,但是在我这边就没有你所说的问题,头文件里不需要包含stdafx.h,要不要我把代码发给你看看
      

  6.   

    编译前把预编译头文件去掉,rebuilderall后再恢复过来就OK了,没错,我以前这样用的就OK!
      

  7.   

    confident_man(康飞特曼) :
        不行,我这个按照你那中办法不能行。
    又有了另外的错误:g:\hotel_mis\stdafx.cpp(9) : error C2857: '#include' statement specified with the /Ycstdafx.h command-line option was not found in the source file
    Error executing cl.exe.
    搞不懂是怎么回事。
      

  8.   

    在我工程文件夹里面自动添加了两个文件,msado15.tli和msado15.tlh,这是什么?是否需要在这两个东西上下工夫?
      

  9.   

    错误了
    以下两种解决方法:
    1.在stdafx.h中包含 <comdef.h>文件
    2.不要import msado15.dll文件,而要import msado20.tlb文件
      

  10.   

    刚才 我把每个文件里 #include "stdafx.h" 注释掉 编译了一次,然后再加上,再编译的时候就出现了下面这个错误:
    DLGBookIn.cpp
    g:\hotel_misffffff\dlgbookin.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'Debug/Hotel_MIS.pch': No such file or directory
     
      在每个文件里的 #include "stdafx.h" 处都有这个错误提示。请问高手,这是什么原因?可不可仪把 .aps .ncb 和.opt 这几个文件删了再建。
      

  11.   

    ukyoking(累) :
       
        谢谢你。
    你发给我的代码我看了,现在问题基本解决了,我原来是在 stdafx.h里面加入 了 “#include ‘chotel-mis。h’ 
     extern chotel-misap theapp;” 
     我把这两句删了就行了。