///////////////////////////////////////////////////////////////// // _ComClient.cpp - client for component ATLDemo7 // // uses _com_ptr, _com_error, and _bstr_t // // // // Platform: Dell Dimension 8100, Windows 2000, SP2 // // Application: Demonstration of ATL 7.0 for CSE775 // // Modified: Jim Fawcett, Syracuse Univ, CST 2-187 // // (315) 443-3948, fawcett@ecs.syr.edu // ///////////////////////////////////////////////////////////////// #include "stdafx.h" #include #include ////////////////////////////////////////////////////// // import creates wrappers for interface methods // and declares _com_ptr _com_error objects #import "..\debug\ATLDemo7.tlb" no_namespace using namespace std; int _tmain(int argc, _TCHAR* argv[]) { cout << "\n Testing in-proc component built with ATL 7.0 " << "\n Sending string and getting back modification " << "\n ================================================\n" << endl; // Initialize COM Library CoInitialize(NULL) ; wstring prefix = L"\n Client: \t"; try { IDemo7Ptr pIDemo7(_T("ATLDemo7.Demo7.1")); if(pIDemo7) { _bstr_t bstr = "Message from CComClient"; wcout << prefix << L"sending: " << (wchar_t*)bstr; pIDemo7->putString(bstr); BSTR Bstr; pIDemo7->getString(&Bstr); bstr = Bstr; wcout << prefix << (wchar_t*)bstr << endl; } else { throw "could not create Demo7 instance"; } } catch(_com_error e) { cout << "\n " << e.ErrorMessage() << "\n\n"; } CoUninitialize() ; cout << "\n\n"; return 0; }