///////////////////////////////////////////////////////////////// // 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 "stdafx.h" #include #include #include "..\ATLDemo7.h" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { cout << "\n Testing in-proc component built with ATL 7.0 " << "\n Sending string and getting back modification " << "\n ================================================\n" << endl; // Initialize COM Library CoInitialize(NULL) ; wstring prefix = L"\n Client: \t"; try { CComQIPtr pIDemo7; pIDemo7.CoCreateInstance(CLSID_Demo7); // note: Used as instance, not as smart pointer, e.g.: dot notation if(pIDemo7) { CComBSTR bstr = "Message from CComClient"; wcout << prefix << L"sending: " << (wchar_t*)bstr; HRESULT hr; hr = pIDemo7->putString(bstr); if(!SUCCEEDED(hr)) throw "call to putString(BSTR) failed"; hr = pIDemo7->getString(&bstr); if(!SUCCEEDED(hr)) throw "call to getString(BSTR*) failed"; wcout << prefix << (wchar_t*)bstr << endl; } else { throw "could not create Demo7 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 ; }