///////////////////////////////////////////////////////////////// // ConsoleClient.cpp - talks to ATLhostOutProc // // // // Language: C++, COM/IDL // // Platform: Dell Dimension 9200, WinXP, SP2 // // Application: Demonstration for CSE775 - Distrib. Objs // // Author: Jim Fawcett, Syracuse Univ, CST 2-187 // // (315) 443-3948, jfawcett@twcny.rr.com // // created: 01 Apr 07 // ///////////////////////////////////////////////////////////////// #include #include #include #include "../ATLhostOutProc/ATLhostOutProc.h" using namespace std; void main() { cout << "\n Demonstrating Helpers for Project #2: " << "\n =======================================\n"; cout << "\n - Console Client calls ATLhostOutProc interface " << "\n to request it to invoke each of two InProc components: " << "\n - ATLechoInProc echos an input string with modifications" << "\n - Inproc_Ex1, a raw C++ inproc component, pops up a" << "\n MessageBox and returns a string.\n"; HRESULT hr; CoInitialize(NULL); { // Create ATLhost OutOfProc Component CComQIPtr pIATLhost; pIATLhost.CoCreateInstance(CLSID_ATLhost); if(pIATLhost) { std::cout << "\n got ATLhost pointer"; // request host to invoke ATLechoInproc Component CComBSTR str1(L"string from ConsoleClient"); hr = pIATLhost->invokeEcho(&str1); if(SUCCEEDED(hr)) std::cout << "\n invokeEcho succeeded"; else std::cout << "\n invokeEcho failed"; std::wcout << L"\n " << str1.Detach(); // request host to invoke Inproc_Ex1 component CComBSTR str2(L"another string from client"); hr = pIATLhost->invokeFx(str2); if(SUCCEEDED(hr)) std::cout << "\n invokeFx succeeded"; else std::cout << "\n invokeFx failed"; CComBSTR str3; hr = pIATLhost->invokeFy(&str3); if(SUCCEEDED(hr)) { std::cout << "\n invokeFy succeeded"; std::wcout << "\n " << str3.Detach(); } else std::cout << "\n invokeFy failed"; std::cout << "\n\n"; } } CoUninitialize(); }