/////////////////////////////////////////////////////////////// // ATLclient2.cpp - client of IString interface // // ver 1.0 // // // // demonstrate creation of simple ATL-based, in-process // // component. This client uses CComQIPtr and CComBSTR // // classes. // // // // Language: Visual C++, ver 6.0, SP 5.0 // // Platform: Dell Dimension 8100, Win2000, SP2 // // Application: Demo: CSE791 - Distributed Objects // // Author: Jim Fawcett, CST 2-187, Syracuse Univ. // // (315) 443-3948, jfawcett@twcny.rr.com // /////////////////////////////////////////////////////////////// #include #include #include #include #include "ATLStrings.h" using namespace std; int main() { cout << "\n Testing ATLStrings inproc component " << "\n using ATL smart pointer, CComQIPtr " << "\n =====================================\n" << endl; // Initialize COM Library CoInitialize(NULL) ; wstring prefix = L" Client: \t\t"; try { CComQIPtr pIString; pIString.CoCreateInstance(CLSID_String); if(pIString) { HRESULT hr; hr = pIString->Fx(L"message from client"); if(!SUCCEEDED(hr)) throw "call to Fx() failed"; CComBSTR bstr; hr = pIString->Fy(&bstr); if(!SUCCEEDED(hr)) throw "call to Fy() failed"; wcout << prefix << (wchar_t*)bstr << endl; } else throw "could not create component 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 ; }