/////////////////////////////////////////////////////////////// // client.cpp - client for component inproc3 // // // // 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 "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"; cout << prefix + "Call to CoCreateInstance to create" << endl; cout << prefix + " component and get interface ISum." << endl; ISum* pISum = NULL ; HRESULT hr = ::CoCreateInstance(CLSID_CSE791, NULL, CLSCTX_INPROC_SERVER, IID_ISum, (void**)&pISum) ; if (SUCCEEDED(hr)) { cout << prefix + "Succeeded getting ISum." << endl; int z; hr = pISum->Sum(3,4,&z) ; if(SUCCEEDED(hr)) cout << prefix + "received " << z << " as sum of 3 and 4" << endl; else cout << prefix + "Client: call to Sum failed" << endl; } else { cout << prefix + "Could not get interface ISum." << endl; } cout << prefix + "Release ISum interface." << endl; pISum->Release() ; // Uninitialize COM Library CoUninitialize() ; cout << endl; return 0 ; }