www.pudn.com > sqlcommand.zip > VOConnection.cpp
//------------------------------------------------------------------- // VOConnection implementation //------------------------------------------------------------------- // // Copyright ©2000 Virtual Office Systems Incorporated // All Rights Reserved // // This code may be used in compiled form in any way you desire. This // file may be redistributed unmodified by any means PROVIDING it is // not sold for profit without the authors written consent, and // providing that this notice and the authors name is included. // // This code can be compiled, modified and distributed freely, providing // that this copyright information remains intact in the distribution. // // This code may be compiled in original or modified form in any private // or commercial application. // // This file is provided "as is" with no expressed or implied warranty. // The author accepts no liability for any damage, in any form, caused // by this code. Use it at your own risk. //------------------------------------------------------------------- #include "stdafx.h" #include "SQLCommand.h" #include "VOConnection.h" #include#include #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif const IID IID__Connection = { 0x113033de, 0xf682, 0x11d2, { 0xbb, 0x62, 0x00, 0xc0, 0x4f, 0x68, 0x0a, 0xcc}}; void __stdcall _com_issue_error(HRESULT m_hr) { TCHAR pcszError[1024]; _stprintf(pcszError, TEXT("_com_issue_error(%ld)\n"), m_hr); OutputDebugString(pcszError); } BOOL CVOConnection::g_Init = FALSE; CLSID CVOConnection::g_ClsID; TCHAR* CVOConnection::g_ProgID = TEXT("ADOCE.Connection.3.0"); ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CVOConnection::CVOConnection(LPCTSTR pcszProvider) : m_Conn(NULL) { if(!g_Init) Initialize(); HRESULT hr; if(pcszProvider == NULL) pcszProvider = TEXT("cedb"); hr = CoCreateInstance(g_ClsID, NULL, CLSCTX_INPROC_SERVER, IID__Connection, (LPVOID*) &m_Conn); hr = m_Conn->put_Provider((LPTSTR)pcszProvider); hr = m_Conn->Open(TEXT(""),TEXT(""),TEXT(""),adOpenUnspecified); } CVOConnection::~CVOConnection() { if(m_Conn) { m_Conn->Close(); m_Conn->Release(); } } BOOL CVOConnection::Initialize() { if(FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) return FALSE; HRESULT hr; hr = CLSIDFromProgID(g_ProgID, &g_ClsID); if(FAILED(hr)) return FALSE; return TRUE; }