编写VC ADO 时,在生成MFC多文档应用程序时应将向导第三页中的Automation选项选上才能支持数据库,但在一开始生成MFC时我忘选了Automation,请问怎么才能在已有的程序中把设置改过来

解决方案 »

  1.   

    实例化ado前调用CoInitialize程序退出后调用CoUninitialize
      

  2.   

    在stdafx.h头文件中加入
    #import "c:\program files\common files\system\ado\msado15.dll" \
    no_namespace rename("EOF","adoEOF")
      

  3.   

    在stdafx.h中加入:
    #ifndef IMPLEMENT_OLECREATE2
    #define IMPLEMENT_OLECREATE2(class_name, external_name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
    AFX_DATADEF COleObjectFactory class_name::factory(class_name::guid, \
    RUNTIME_CLASS(class_name), TRUE, _T(external_name)); \
    const AFX_DATADEF GUID class_name::guid = \
    { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } };
    #endif // IMPLEMENT_OLECREATE2#import "c:\program files\common files\system\ado\msado15.dll" \
    no_namespace rename("EOF","adoEOF")然后在应用对象的InitInstance的开头加上
    if (!AfxOleInit())
    {
    AfxMessageBox(IDP_OLE_INIT_FAILED);
    return FALSE;
    } // Parse the command line to see if launched as OLE server
    if (RunEmbedded() || RunAutomated())
    {
    // Register all OLE server (factories) as running.  This enables the
    //  OLE libraries to create objects from other applications.
    COleTemplateServer::RegisterAll();
    }
    else
    {
    // When a server application is launched stand-alone, it is a good idea
    //  to update the system registry in case it has been damaged.
    COleObjectFactory::UpdateRegistryAll();
    }