?????: VC ++ ??? #import ?? ?????? ActiveX ???? ???????? (ADO) ?? ????? ????

???? ?????? ???? ??????
???? ID: 169496 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

????? C++ ??? #import directive OLE ????? ??? ???-??? ?? ??? ?? ????? ?? ??????? ???????? ???? ??? ActiveX ???? ???????? (ADO) ?? ??? ????? ???? ???? ??, ??, ?? ???? ???? ??????? #import ??? ????? ?? ???? ???? ?? ???? ????? ???? ?? ???? ADO ?? ??? #import ?? ??? ???? ?? ??? ?????? ???

???? ???????

?? Instantiate Any ???? ????? ?? #import ???? ?? ????

OLE ???? #import ?????? ???? ?? ?? ???? ?? ?????????? ?? ????? ?? ???? ?? ??????? ???? ?? ??? ?????????? ??? ?????? ?? ???, ????? ??? ???????? ??, ??? #import ??????? ???? declares, initializes OLE, ?? ???? ??? ??????? ???? instantiates ?? ??? ???:

   // Declare smart pointer of Recordset
    _RecordsetPtr     p;

   void main( void )
   {
      // Initialize OLE.
      ::CoInitialize(NULL);

      // Instantiate smart pointer.
      HRESULT hr = p.CreateInstance( __uuidof( Recordset ) );

      ...
   }
				
???? ??? ????? ???, ??? ??, ???????? ?? ?? unhandled ????? ????? ??? ??????? ??????? ???? p ?? declared ?? ????? (?????? virtue ?? ??? constructor ??? ??? ??????? uuid ?? ??? ??) ???? ????:

// Declare & instantiate smart pointer of Recordset
    _RecordsetPtr     p( __uuidof( _Recordset ) );

   void main( void )
   {
      // Initialize OLE
      ::CoInitialize(NULL);

      ...
   }
				
P ??? ?? ??????? ?? ??, ??????? ??? ?? ???? ???? ?? ???? CoInitialize main() ??? ??? ??? ???? ??? ?? ??? ?? ???? ?? ????? ??? snippet ?? ???:
struct InitOle {
      InitOle()  { ::CoInitialize(NULL); }
      ~InitOle() { ::CoUninitialize();   }
    } _init_InitOle_;

   // Declare & instantiate smart pointer of Recordset
    _RecordsetPtr     p( __uuidof( _Recordset ) );

   ...
				
Struct InitOle ?? ??????? declared ??, ?? p ???? ?? ???? ???? ????, ??, ?????? ???? constructor ??? OLE initializes. ?? ?????? ?? fail-safe, ???? ???? ????? ?????? ????? ????? ????:
[?????????] (KERNEL32.DLL) ??? ????? unhandled: 0xE06D7363
Microsoft C++ ??????

#Import ?? ??? ?????????????

???? ????????? ??? ADO ?? ??? ?? ??????? ???? ?? ??? ?????????? ??, ?? ??????? ????????? ???? ????? ??? ????????? ???? ?? ?? ??? ????? ?? Msado10.dll MSADO15.dll #import ?? ????? ???? ?? ???:

   #import <msado15.dll>            \ 
   no_namespace                     \ 
  rename( "EOF", "adoEOF" )
				

?????? ????????

ADO, ?? ??? ??? ADO ???? ?? ?? HRESULT ??? ??? ?????? ??????? ?? ???? ??, ?? ????? ??????? #import ???? ?? ??? ??????? ?? ???? ??, ?? ???? ?? ?????? ?? ??? ADO ????????? ?????? ????????? ???? ?? ???? ??? ????????? ?????? ?? ??????? ???? ?? ??? ???? ?? ????? ??????? ???????? ?? ???????? ??? ???? ??????? ?? ??? ????? ????? ???? ?? Microsoft ???????? ??? ?????:

169498: ????? ?????? ?? ??? ?? ?????? ??????? ??? VC ++ ADO ?? #import ?? ???

ADO ?? Dbdaoint.h

(#Import) ?????? ADO ?? MFC DAO ?? DAO SDK ??? ???? ??????????? ?????, ?? ?? ??? ??? ???? ???? ?? ?????? ???? ??:

  #include <afxdao.h>  // MFC DAO
   // -or-
  #include <dbdao.h>   // DAO SDK

  #import <msado15.dll> no_namespace ...
				

?? ????? ????????? ??????? ????:

C2011 ??????: 'EditModeEnum': '???' redefinition ???? ????
C2011 ??????: 'LockTypeEnum': '???' redefinition ???? ????
C2011 ??????: 'FieldAttributeEnum': '???' redefinition ???? ????
C2011 ??????: 'DataTypeEnum': '???' redefinition ???? ????
C2011 ??????: 'ParameterDirectionEnum': '???' redefinition ???? ????
C2011 ??????: 'RecordStatusEnum': '???' redefinition ???? ????
??????? ??? ????? ???? ???? ??, ?? ?? enumerated ?????? ??? ???????? ??? ???? ADO ?????? ?????? ?? ?? DAO ?????? ?????? ?? ?? ???? ?? ??? ??????? ??? ??? ???? ??? ?? ?? ?? ???? ?? ??? ?? ?????? ???:

  • ??? ADO ?? DAO ??? ??? .cpp ??????? ???? # <afxdao.h bdao.h="">?? ??? ??? ??? ??????????? ??????? ???</afxdao.h> ????? ???? ?? #import ?? ????? ???? ???? well.
  • ADO ?? ??? ??????? ??? ?? ??? ???? ??? ????? ?? ????? ?? ??? #import ??? ?? ??????? ????? ???? ???? ?? ?? ?? ?? ??? ADO ???????? ??? ?? ?????? ???? ????? ?? ?? ??? ??? ???????? ??? ????? ?? ???????? ???? ????? ????? ADO ?? ???? ??? ??? ?????? ?? ????? ???? ?? ??? ???? ?????? ??? ????? ?? mix-??-????? ADO ?? DAO ?????????? ?? ??? ???? ????? ?? ???? ?? ??? ADO ???? ?? enumerated ?????? ?? ??? ADO ??? ????? ?? ?????? ??? ?? ?????? ?? ????:

       #include <afxdao.h>
    
          #import <msado15.dll>                            \ 
                  rename_namespace("AdoNS") rename( "EOF", "adoEOF" )
    
          void ADOOnly( void )
          {
              using namespace AdoNS;
    
              _RecordsetPtr   prs;
    
              // Generates Compile Errors:
              CDaoRecordset   rs;
          }
    
          void MixAdoAndDao( void )
          {
              AdoNS::_RecordsetPtr  prs;
    
              // Compiles just fine
              CDaoRecordset   drs;
          }
    						
Dissecting ?? using Msado105.tlh/Msado15.tli--------------------------------------------

#import ????? ???????, Msado105.tlh ?? Msado15.dll ?? ???? typelib ?? ??? Msado15.tli ????? ??? .Tlh ???? ?? ???? ?? ???? ?? ??????? ???????????:
  • ??? ?????? ?? Typedefs
  • ??????? ???? Typedef ?? Declarations
  • ?????? ????????? ????
???????? ??? ???? ??? ?? ??????? ????? ???? ??? ???

??? ?????? ?? Typedefs

??? ?????? ?? Typedefs ???? ???? ??? ?? GUID struct __declspec(uuid("...")) ?? ????? ?? ???? ?? ????? ????????, ????????, ?? ??? ?? CoClass typelib ??? ????????? ???

   ...
   struct __declspec(uuid("00000274-0000-0010-8000-00aa006d2ea4"))
   /* dual interface */ _Connection;
   ...
   struct __declspec(uuid("00000275-0000-0010-8000-00aa006d2ea4"))
   /* interface */ ICADOConnection;
   ...
   struct /* coclass */ Connection;
   ...
				
??? ???????, ???? ???????, ??? ?? ?? ???? ??????? ??? ?? typelib ?? ?????? ???? ??, ????? ?? ??? ADO ??????? ???????? ??? ?? implemented ???? ????? ???????? ?? coclass ?? ??? ??? ???

??????? ???? TypeDef Declarations

??????? ?? ????? ???????, ?? ??? ??????? ???? ??? declared, ?? ?? simplifies ??????? ?? ????? ????:
   ...
   _COM_SMARTPTR_TYPEDEF(_Connection, __uuidof(_Connection));
   ...
   _COM_SMARTPTR_TYPEDEF(ICADOConnection, __uuidof(ICADOConnection));
   ...
				
????? ??? ?? coclass ??????? ??????? ?? ??? ??? ??????? ???? declared ???? ??? ???

?????? ????????? ????

?? ??????? ???? ?? typelib ?????? ?? well ??????????? ?? ??? ??? ????????? typelib ??? ???? ?? enumerated ???????? ??? ????? ???:

enum CursorTypeEnum
   {
      adOpenUnspecified = -1,
      adOpenForwardOnly = 0,
      adOpenKeyset = 1,
      adOpenDynamic = 2,
      adOpenStatic = 3
   };

   ...

   struct __declspec(uuid("00000274-0000-0010-8000-00aa006d2ea4"))
   _Connection : _ADO
   {
      // 
      // Property data.
      // 
      _declspec(property(get=GetConnectionString,
                         put=PutConnectionString))
      _bstr_t ConnectionString;
      ...

      // 
      // Wrapper methods for error-handling.
      // 
      _bstr_t GetConnectionString ( );
      void PutConnectionString (
          _bstr_t pbstr );
      ...

      // 
      // Raw methods provided by interface.
      // 
      virtual HRESULT __stdcall get_ConnectionString (
          BSTR * pbstr ) = 0;
      virtual HRESULT __stdcall put_ConnectionString (
          BSTR pbstr ) = 0;
      ...
   };
				
????? ??? fragment, ??? ??? ???? ??? ??????? ????? ?? ConnectionString ?? ??? ??????? ?? ???? ?? ??? declspec ????? ???? ??? ???? ??????? ??? ??????? ?????? ????? ?? #import, ?????? ????? ??? ?? ?? ????????? ?? ??? ????, ?? ??? ?? ??? ???? ??? ?? ??? _com_error ????? ???? ?????? ????????? ??? declares ??????? ?? ???? ?? ?? ???????? ?????? ???

?? ?? GetConnectionString ?? PutConnectionString ??? ???, ??? ?????? ??? ???????? ??? ConnectionString ??? ?? ??????? ?? ???? ?????? ??? ???????????:

   bstrConnect = SysAllocString( L"DSN=AdoDemo;UID=admin;PWD=sa" );
   p->ConnectionString = bstrConnect;
				


GetConnectionString/PutConnectionString ?? ???????? ??????????? Msado15.tli ????? ??? ????? ?? ???? ???

?? ?? ??????? ???????? ?? ??? ???? ??? ?? ????? ???? ?? ??? ??? ??? ??, ?? ??? ??? ????????? Msado15.tlh ??? ????? ??????? ?? ??? ??????? ???? ?? ??????? ????? ???? ???:

   _ConnectionPtr p;
   bstrConnect
   HRESULT           hr = S_OK;
   _ConnectionPtr    pConn;

   hr = pConn.CreateInstance( __uuidof( Connection ) );

      if( !FAILED( hr ) )
         hr = pConn->Open( L"pubs", L"sa", L"" );
				


???? pubs ??? ODBC ???? ????? ???

#import ?? ?????? ??? ?? ??? release()

#Import ?? ??? ?? ?? ?? ?? ???? ?? ????? AddRef, QueryInterface ?? ???? ???? ?? ??? ???????? ??? ?? ??? ???????, ??? release() ?? ?????? ??? ?? ??? ?? ??????? ???? ?? ??? ?? ?????? ???? ???, ??? ???? ??? ???????? ????? ?? ????

_Com_ptr_t ??? ????? ??, m_pInterface ??? #Import ?? ?? ???? ???? ???? ??, ?? ??? ??? ???? ???????? ?? ?????? ??? ????, ???? ?????? ???????? ?? ?????? ??? destroying ???? ???? ???? decrementing ???? ?? ??? m_pInterface ?? ??? ??? distinction ???? ?? ???? ?????? ??? ?? ???? ??? ?????? ()--it--#import ??????? ???? ?? ??? ???? ?????? ??? ?? ?????? AddRef() ???? gladly ???? ?? ?????? ????? ????? ???? ??, interesting ?? ?????? ?? crashing ??????? ??? ??? ?? ?? ???? ???????? ?? ???????

??????? ???????????, ?? ??? ???? AddRef() (?? ???? ?? ???????? ?? ?? ?? ????), ???? ????? ?? ?? ?? ???

??????

  • ?????? ??? ?? ?????? Dale Rogerson ISBN 1-57231-349-8
  • OLE COM ???????? ?????? (Oleview.exe) ???? ???? ?? typelib ?? ??????? ?? ??????? ?? ??? ?? ?? ??? ????? C++ ?? ????
  • ????? C++ ?????? ????????: #import ?? ??? ????
???????? ??????? ?? ??? ?????? ?? Microsoft ???????? ??? ????? ?? ??? ????? ???? ???????? ?? ????? ????:
182389FILE: ADO #import ?? 1.5 ?? Getrows/???????? Adovcbm.exe
184968????????? ???? ?? FILE: Adovcsp.exe ?? ????? ADO ?? ??? ???????????? ???????? ????
186387?? ?????: COM ?? Ado2atl.exe ???? ADO ???????
181733FILE: Adovcbtd.exe #import Using UpdateBatch ?? CancelBatch
166112PRB: EOF ADO ?? ??? #import ?? ????? ???? ??? ?? ??? ?????
168354?????: ?????????? OLE ?? OLEDB ??????? ????????? ???? ????? ADO ??

???

???? ID: 169496 - ????? ???????: 02 ?????? 2010 - ??????: 4.0
???? ???? ???? ??:
  • Microsoft Data Access Components 2.7
??????: 
kbcode kbdatabase kbinfo kbusage kbmt KB169496 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:169496

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com