DOCUMENT:Q170461 23-AUG-2001 [visualc] TITLE :HOWTO: Passing a License Key to Classes Generated by #import PRODUCT :Microsoft C Compiler PROD/VER:winnt:5.0 OPER/SYS: KEYWORDS:kbADO100 kbCompiler kbDatabase kbMFC kbVC500 kbGrpDSVCDB kbGrpDSMDAC kbDSupport ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual C++, 32-bit Enterprise Edition, version 5.0 - Microsoft Visual C++, 32-bit Professional Edition, version 5.0 ------------------------------------------------------------------------------- SUMMARY ======= This article only applies to ADO version 1.0. With ADO 1.5 and above you do not need a licence key. ADO 1.5 and above are redistributed with MDAC(Microsoft Data Access Components) package. So to get the latest version of ADO, download latest version of MDAC from http://www.microsoft.com/data. The Following Information Applies to ADO 1.0 -------------------------------------------- The #import directive is used to incorporate information from a type library, but makes no provision for a license key. If you installed the OLE DB SDK or Internet Information Server 3.0, then the license key is automatically created in the registry. However, if your application is redistributed to machines that have not had either OLE DB SDK or Internet Information Server 3.0 installed on them, you need to programmatically provide the ADO License Key. This is necessary regardless of the development environment you are using to manipulate ADO. This article is one of a series dealing with redistribution of Microsoft Data Access Components (MDAC), including ODBC, OLE DB, ADO, RDS, the MDAC Standalone, MDAC Redistribution, and the Data Access SDK. The white paper "Redistributing Microsoft Data Access Components" presents a comprehensive overview of this subject, including a reference to the content in this Knowledge Base article. You can find this white paper in the Microsoft Developer Network at the following location: http://msdn.microsoft.com/library/techart/msdn_redistmdac.htm MORE INFORMATION ================ The following is a typical #import statement: #import "msado10.dll" no_namespace rename( "EOF", "adoEOF" ) When using #import to generate classes for ADO, your code to manipulate a recordset might look like this: HRESULT hr; _ConnectionPtr pConn; _bstr_t bstrConnect = SysAllocString( L"driver={sql server};" L"Database=pubs;" L"UID=sa;PWD=;" ); hr = pConn.CreateInstance(__uuidof(Connection)); if (!FAILED(hr)) pConn->ConnectionString = bstrConnect; This will work on any machine that has had the ADO 1.0 License Key already installed. However, if the license key is not installed, this code will not work. The code sample below is functionally equivalent but demonstrates how to create an ADO object using a license key. Sample Code ----------- BSTR LicKey; IClassFactory2 *pIUnknown = NULL; IUnknown *pOuter = NULL; HRESULT hr; _ConnectionPtr pConn; _bstr_t bstrConnect = SysAllocString( L"driver={sql server};" L"Database=pubs;" L"UID=sa;PWD=;" ); LicKey = SysAllocString( L"gxwaezucfyqpwjgqbcmtsncuhwsnyhiohwxz" ); // hr = CoGetClassObject( __uuidof(Connection), CLSCTX_INPROC_SERVER, NULL, IID_IClassFactory2, reinterpret_cast(&pIUnknown) ); if( !FAILED( hr ) ) { pIUnknown->CreateInstanceLic( pOuter, NULL, __uuidof(_Connection), LicKey, reinterpret_cast>void**> (&pConn) ); } if( !FAILED( hr ) ) pConn->ConnectionString = bstrConnect; SysFreeString( LicKey ); REFERENCES ========== Additional query words: adoengdb ====================================================================== Keywords : kbADO100 kbCompiler kbDatabase kbMFC kbVC500 kbGrpDSVCDB kbGrpDSMDAC kbDSupport Technology : kbVCsearch kbAudDeveloper kbVC500 kbVC32bitSearch kbVC500Search Version : winnt:5.0 Issue type : kbhowto ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2001.