我用 vc 创建一个扩展MFC (dll)
在 DllMain函数中使用
if(!AfxOleInit())
return -1;然后在这个文件的头部使用
#import "C:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF","adoEOF")  
结果出现编译错误
如果生成MFC(exe)则没有此错误,我还有什么库没有导入么?
错误如下
c:\documents and settings\administrator\桌面\testdll\adobaseset.h(15) : error C2143: syntax error : missing ',' before '&'
c:\documents and settings\administrator\桌面\testdll\adobaseset.h(15) : error C2059: syntax error : '&'
c:\documents and settings\administrator\桌面\testdll\adobaseset.h(19) : error C2146: syntax error : missing ';' before identifier 'm_pRecordset'
c:\documents and settings\administrator\桌面\testdll\adobaseset.h(19) : error C2501: '_RecordsetPtr' : missing storage-class or type specifiers
c:\documents and settings\administrator\桌面\testdll\adobaseset.h(19) : error C2501: 'm_pRecordset' : missing storage-class or type specifiers
c:\documents and settings\administrator\桌面\testdll\adobaseset.h(20) : error C2146: syntax error : missing ';' before identifier 'm_pConnection'
c:\documents and settings\administrator\桌面\testdll\adobaseset.h(20) : error C2501: '_ConnectionPtr' : missing storage-class or type specifiers
c:\documents and settings\administrator\桌面\testdll\adobaseset.h(20) : error C2501: 'm_pConnection' : missing storage-class or type specifiers
c:\documents and settings\administrator\桌面\testdll\adobaseset.h(32) : error C2146: syntax error : missing ';' before identifier 'Execute'
c:\documents and settings\administrator\桌面\testdll\adobaseset.h(32) : error C2501: '_RecordsetPtr' : missing storage-class or type specifiers
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(11) : error C2039: 'm_pConnection' : is not a member of 'CADOBaseSet'
        c:\documents and settings\administrator\桌面\testdll\adobaseset.h(11) : see declaration of 'CADOBaseSet'
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(11) : error C2228: left of '.CreateInstance' must have class/struct/union type
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(11) : error C2065: 'Connection' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(14) : error C2227: left of '->Open' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(14) : error C2065: '_bstr_t' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(14) : error C2146: syntax error : missing ')' before identifier 'strSql'
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(14) : error C2059: syntax error : ')'
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(16) : error C2061: syntax error : identifier '_com_error'
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(16) : error C2310: catch handlers must specify one type
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(18) : error C2065: 'e' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(18) : error C2227: left of '->ErrorMessage' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(21) : error C2317: 'try' block starting on line '13' has no catch handlers
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(21) : error C2039: 'm_pRecordset' : is not a member of 'CADOBaseSet'
        c:\documents and settings\administrator\桌面\testdll\adobaseset.h(11) : see declaration of 'CADOBaseSet'
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(26) : error C2039: 'm_pRecordset' : is not a member of 'CADOBaseSet'
        c:\documents and settings\administrator\桌面\testdll\adobaseset.h(11) : see declaration of 'CADOBaseSet'
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(26) : error C2227: left of '->State' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(28) : error C2227: left of '->Close' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(31) : error C2039: 'm_pConnection' : is not a member of 'CADOBaseSet'
        c:\documents and settings\administrator\桌面\testdll\adobaseset.h(11) : see declaration of 'CADOBaseSet'
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(31) : error C2227: left of '->State' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(33) : error C2039: 'm_pConnection' : is not a member of 'CADOBaseSet'
        c:\documents and settings\administrator\桌面\testdll\adobaseset.h(11) : see declaration of 'CADOBaseSet'
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(33) : error C2227: left of '->Close' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(34) : error C2039: 'm_pConnection' : is not a member of 'CADOBaseSet'
        c:\documents and settings\administrator\桌面\testdll\adobaseset.h(11) : see declaration of 'CADOBaseSet'
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(40) : error C2039: 'm_pRecordset' : is not a member of 'CADOBaseSet'
        c:\documents and settings\administrator\桌面\testdll\adobaseset.h(11) : see declaration of 'CADOBaseSet'
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(40) : error C2228: left of '.CreateInstance' must have class/struct/union type
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(40) : error C2065: 'Recordset' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(43) : error C2227: left of '->GetState' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(43) : error C2065: 'adStateOpen' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(44) : error C2227: left of '->Close' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(45) : error C2227: left of '->Open' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(46) : error C2228: left of '.GetInterfacePtr' must have class/struct/union type
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(47) : error C2065: 'adOpenDynamic' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\testDll\ADOBaseSet.cpp(47) : error C2065: 'adLockOptimistic' : undeclared identifier

解决方案 »

  1.   

    估计少了最简单的,在用MFC支持上钩一下。
      

  2.   

    http://topic.csdn.net/t/20040114/15/2663417.html
    看看是不是你想要的
      

  3.   

    我创建的工程是MFC(dll),MFC扩展(dll)
    #include "stdafx.h"
    #import "C:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF","adoEOF")  
    #include <afxdllx.h>#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    static AFX_EXTENSION_MODULE TestDllDLL = { NULL, NULL };extern "C" int APIENTRYDllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
    {
    // Remove this if you use lpReserved
    UNREFERENCED_PARAMETER(lpReserved);
    if(!AfxOleInit())
    return -1;
    if (dwReason == DLL_PROCESS_ATTACH)
    {
    TRACE0("TESTDLL.DLL Initializing!\n");

    // Extension DLL one-time initialization
    if (!AfxInitExtensionModule(TestDllDLL, hInstance))
    return 0; // Insert this DLL into the resource chain
    // NOTE: If this Extension DLL is being implicitly linked to by
    //  an MFC Regular DLL (such as an ActiveX Control)
    //  instead of an MFC application, then you will want to
    //  remove this line from DllMain and put it in a separate
    //  function exported from this Extension DLL.  The Regular DLL
    //  that uses this Extension DLL should then explicitly call that
    //  function to initialize this Extension DLL.  Otherwise,
    //  the CDynLinkLibrary object will not be attached to the
    //  Regular DLL's resource chain, and serious problems will
    //  result. new CDynLinkLibrary(TestDllDLL);
    }
    else if (dwReason == DLL_PROCESS_DETACH)
    {
    TRACE0("TESTDLL.DLL Terminating!\n");
    // Terminate the library before destructors are called
    AfxTermExtensionModule(TestDllDLL);
    }
    return 1;   // ok
    }
      

  4.   

    我改成如此也错~
    #include "stdafx.h"
    #include <afxdllx.h>
    #import "C:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF","adoEOF")  
      

  5.   

    #import "C:\Program Files\Common Files\System\ADO\MSADO15.DLL" rename_namespace("yourADO") rename("EOF","EndOfFile")
      

  6.   

    把#import语句放到stdafx.h里面去
      

  7.   

    #import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF") 
      

  8.   

    放到#import "C:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF","adoEOF")
    STDAFX.H后
    出现如下错误
    c:\documents and settings\administrator\桌面\testdll\debug\msado15.tlh(171) : error C2011: 'LockTypeEnum' : 'enum' type redefinition
    c:\documents and settings\administrator\桌面\testdll\debug\msado15.tlh(214) : error C2011: 'DataTypeEnum' : 'enum' type redefinition
    c:\documents and settings\administrator\桌面\testdll\debug\msado15.tlh(258) : error C2011: 'FieldAttributeEnum' : 'enum' type redefinition
    c:\documents and settings\administrator\桌面\testdll\debug\msado15.tlh(279) : error C2011: 'EditModeEnum' : 'enum' type redefinition
    c:\documents and settings\administrator\桌面\testdll\debug\msado15.tlh(287) : error C2011: 'RecordStatusEnum' : 'enum' type redefinition
    c:\documents and settings\administrator\桌面\testdll\debug\msado15.tlh(407) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
    c:\documents and settings\administrator\桌面\testdll\debug\msado15.tlh(531) : error C2011: 'ParameterDirectionEnum' : 'enum' type redefinition
      

  9.   

    是不是在import之前你已经包含了某些数据库头文件?比如dbdaoint.h
      

  10.   

    在Stdafx.h中注释掉这些关于数据库的包含
    这些都是向导生成的
    #ifndef _AFX_NO_DB_SUPPORT
    #include <afxdb.h> // MFC ODBC database classes
    #endif // _AFX_NO_DB_SUPPORT#ifndef _AFX_NO_DAO_SUPPORT
    #include <afxdao.h> // MFC DAO database classes
    #endif // _AFX_NO_DAO_SUPPORT