///////////////////////////////////////////////////////////////////// // CallDotNet.cpp - Implementation of C++ client for // // IHello interface, using COM to .Net interop // // // // Jim Fawcett, CSE775 - Distributed Objects, Spring 2004 // ///////////////////////////////////////////////////////////////////// #import "..\CSharpLib\bin\debug\CSharpLib.tlb" no_namespace named_guids #include #include void main() { std::cout << "\n Calling C# Class Method from COM Client"; std::cout << "\n =========================================\n"; try { ::CoInitialize(NULL); HRESULT hr = S_OK; IHello* pHello = NULL; hr = ::CoCreateInstance( CLSID_CHello,NULL,CLSCTX_ALL,IID_IHello,(void**)&pHello ); if(!SUCCEEDED(hr)) throw std::exception("CoCreateInstance failed"); hr = pHello->sayHello(); if(!SUCCEEDED(hr)) throw std::exception("Call to sayHello() failed"); pHello->Release(); ::CoUninitialize(); } catch(std::exception& e) { std::cout << "\n " << e.what() << "\n\n"; } std::cout << "\n press key to quit: "; char ch; std::cin >> ch; }