///////////////////////////////////////////////////////////////// // CComClient.cpp - client for component ATLDemo7 // // uses CComQIPtr and CComBSTR // // // // Platform: Dell Dimension 8100, Windows 2000, SP2 // // Application: Demonstration of ATL 7.0 for CSE775 // // Modified: Jim Fawcett, Syracuse Univ, CST 2-187 // // (315) 443-3948, fawcett@ecs.syr.edu // ///////////////////////////////////////////////////////////////// #include "..\Q1\stdafx.h" #include #include #include "..\Q1\Q1.h" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { wcout << L"\n Using Array of BSTRs to pass Semi-Expressions " << L"\n ===============================================\n" << endl; // Initialize COM Library CoInitialize(NULL) ; wstring prefix = L"\n Client: \t"; try { CComQIPtr pSF; pSF.CoCreateInstance(CLSID_ScanFile); // note: Used as instance, not as smart pointer, e.g.: dot notation if(pSF) { CComBSTR file = "CComClient.cpp"; wcout << L"Processing file: " << (wchar_t*)file << endl; HRESULT hr; hr = pSF->putFile(file); if(!SUCCEEDED(hr)) throw "call to putFile(BSTR) failed"; ULONG size = 0; do { BSTR* pBSTR = 0; hr = pSF->get(&size, &pBSTR); if(!SUCCEEDED(hr)) throw "call to get(UINT*, BSTR**) failed"; else { wcout << "\n"; for(ULONG i = 0; i 0); wcout << endl; } else { throw "could not create ScanFile instance"; } } catch(const char* msg) { cout << "\n " << msg << "\n\n"; } // Uninitialize COM Library // Note: If you declare CComQIPtr in the same scope as CoInitialize // and CoUninitialize(), then you must call pIString.Release() before // calling CoUninitialize(). If declared in a nested scope, as here, // the destructor, ~CComQIPtr() will call release for you, when it // leaves the inner scope. CoUninitialize() ; cout << "\n\n"; return 0 ; }