///////////////////////////////////////////////////////////////////// // Client.cpp #include "../Q1/stdafx.h" #include #include #include "../Q1/Q1.h" using namespace std; int main(int argc, char* argv[]) { cout << "\n Client that starts a legacy tool wrapper " << "\n ==========================================\n" << endl; // Initialize COM Library CoInitialize(NULL) ; wstring prefix = L"\n Client: \t"; try { CComQIPtr pIWrapper; pIWrapper.CoCreateInstance(CLSID_Wrapper); // note: Used as instance, not as smart pointer, e.g.: dot notation if(pIWrapper) { CComBSTR bstr = "Tool Arguments: "; for(int i=1; istart(bstr); if(!SUCCEEDED(hr)) throw "call to start(BSTR) failed"; hr = pIWrapper->collectResults(&bstr); if(!SUCCEEDED(hr)) throw "call to getResults(BSTR*) failed"; wcout << prefix << (wchar_t*)bstr << endl; } else { throw "could not create Wrapper 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 pIWrapper.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 ; }