// MyObjectClient.cpp : // Illustrates full COM compatibility // // std::out etc #include #include #include #include "MultiInterface_i.c" #include "MyObject.h" void pause (); int main(int argc, char* argv[]) { HRESULT hr; IFoo* pIFoo = NULL; IGoo* pIGoo = NULL; CoInitialize( NULL ); hr = CoCreateInstance( CLSID_MyObject, NULL, CLSCTX_ALL, IID_IFoo, reinterpret_cast (&pIFoo)); if ( !SUCCEEDED(hr) ) { std::cout << "ERROR: Unable to create MyObject instance!!\n"; switch(hr) { case REGDB_E_CLASSNOTREG: std::cout << " Class not registered.\n"; break; case E_NOINTERFACE : std::cout << " No such interface implemented.\n"; break; case CLASS_E_NOAGGREGATION : std::cout << " No aggregation.\n"; break; default: std::cout << " Unexpected error.\n"; break; } } else { cout << "Retrieved pointer to IFoo interface\n"; hr = pIFoo->Func1(); pause(); if (FAILED (hr)) cout << "Func1() cannot be called" << endl << endl; else { pIFoo->Func1(); pause(); pIFoo->Func1(); pIFoo->Func1(); cout << "Func1 called 3 times\n\n"; hr = pIFoo->QueryInterface (IID_IGoo, reinterpret_cast (&pIGoo)); if ( !SUCCEEDED(hr) ) { std::cout << "ERROR: Unable to return pointer to IGoo!!\n"; } else { pause(); pIGoo->Gunc(); cout << "Gunc called\n\n"; pIGoo->Release(); pIGoo = NULL; } pIFoo->Release(); pIFoo = NULL; } } CoUninitialize(); return 0; } void pause () { for (int i = 0; i <= 10000000; i++) int j = int (sqrt (2)); }