/////////////////////////////////////////////////////////////// // client.cpp - client for component inproc_Ex1 // // // // Platform: Micron Dual Pentium 200, WinNT 4.0, SP3 // // Application: Demonstration for CSE791 - Distrib. Objs // // Authors: Eddon & Eddon, Inside Distributed COM, // // Microsoft Press, 1998 // // Modified: Jim Fawcett, Syracuse Univ, CST 2-187 // // (315) 443-3948, fawcett@ecs.syr.edu // /////////////////////////////////////////////////////////////// #include #include #include #include "..\component\cmpnt.h" using namespace std; int main() { cout << "\n Testing in-proc component that uses IDL " << "\n to define its interfaces " << "\n =========================================\n" << endl; // Initialize COM Library CoInitialize(NULL) ; string prefix = " Client: \t\t"; wstring Lprefix = L" Client: \t\t"; cout << prefix + "Call to CoCreateInstance to create" << endl; cout << prefix + " component and get interface IString." << endl; IString* pIString = NULL ; HRESULT hr = ::CoCreateInstance(CLSID_inproc1_Ex1, NULL, CLSCTX_INPROC_SERVER, IID_IString, (void**)&pIString) ; if (SUCCEEDED(hr)) { cout << prefix + "Succeeded getting IString." << endl; hr = pIString->Fx(L"message from client") ; if(SUCCEEDED(hr)) cout << prefix + "Fx call succeeded" << endl; else cout << prefix + "Client: call to Fx failed" << endl; BSTR bstr = 0; hr = pIString->Fy(&bstr) ; if(SUCCEEDED(hr)) { cout << prefix + "Fy call succeeded" << endl; wcout << Lprefix + L" " << bstr << endl; wcout << Lprefix + L"free BSTR memory" << endl; SysFreeString(bstr); } else cout << prefix + "Client: call to Fx failed" << endl; } else { cout << prefix + "Could not get interface IString.\n\n"; CoUninitialize() ; return 1; } // cout << prefix + "Release IString interface." << endl; pIString->Release() ; // Uninitialize COM Library CoUninitialize() ; cout << endl; return 0 ; }