///////////////////////////////////////////////////////////////////////// // CoGetObject.cpp - Activates an Object using CoGetObject // // ver 1.0 // // // // Eddon and Eddon, Inside Distributed COM, Microsoft Press, 1998 // // // // Modifed by Jim Fawcett, Syracuse University, jfawcett@twcny.rr.com // // CSE775 - Distributed Objects, Spring 2005 // ///////////////////////////////////////////////////////////////////////// #define _WIN32_DCOM #include #include #include "Component\component.h" using namespace std; void main() { cout << "\n Activating COM Object using CoGetObject " << "\n =========================================\n"; CoInitialize(NULL); OLECHAR string[] = L"clsid:10000002-0000-0000-0000-000000000001"; IClassFactory* pClassFactory; CoGetObject(string, 0, IID_IClassFactory, (void**)&pClassFactory); ///////////////////////////////////////////////////////////////////////// // IBindCtx* pBindCtx; // CreateBindCtx(0, &pBindCtx); // // ULONG eaten; // IMoniker* pMoniker; // // HRESULT hr = MkParseDisplayName(pBindCtx, string, &eaten, &pMoniker); // if(FAILED(hr)) // { // cout << "MkParseDisplayName failed" << endl; // exit(0); // } // // IClassFactory* pClassFactory; // pMoniker->BindToObject( // pBindCtx, NULL, IID_IClassFactory, (void**)&pClassFactory // ); ///////////////////////////////////////////////////////////////////////// ISum* pSum; pClassFactory->CreateInstance(NULL, IID_ISum, (void**)&pSum); int addition; pSum->Sum(23, 32, &addition); cout << "23 + 32 = " << addition << endl; pSum->Release(); pClassFactory->Release(); CoUninitialize(); }