///////////////////////////////////////////////////////////////////////// // client.cpp - Demonstrates Activation with a Custom Class Object // // ver 1.0 that accepts an argument, like a constructor. // // // // Eddon and Eddon, Inside Distributed COM, Microsoft Press, 1998 // // // // Modifed by Jim Fawcett, Syracuse University, jfawcett@twcny.rr.com // // CSE791 - Distributed Objects, Spring 2002 // ///////////////////////////////////////////////////////////////////////// #define _WIN32_DCOM #include #include "Component\component.h" using namespace std; void main() { cout << "\n Demonstrates Activation of a COM Object using a Custom " << "\n Class Object that does not implement IClassFactory(2) " << "\n ========================================================\n"; cout << "Client: Calling CoInitialize()" << endl; CoInitialize(NULL); // Always need a bind context IBindCtx* pBindCtx; CreateBindCtx(0, &pBindCtx); // Convert the string to a moniker ULONG eaten; IMoniker* pMoniker; OLECHAR string[] = L"clsid:10000013-0000-0000-0000-000000000001"; MkParseDisplayName(pBindCtx, string, &eaten, &pMoniker); // Bind the moniker to the named object - NOTE: no IClassFactory(2) IPrimeFactory* pPrimeFactory; pMoniker->BindToObject( pBindCtx, NULL, IID_IPrimeFactory, (void**)&pPrimeFactory ); // Use the custom class object to create a Prime object IPrime* pPrime; int next_prime = 0; // initialize with any prime number pPrimeFactory->CreatePrime(next_prime, &pPrime); // Now we have a Prime object cout << "\n Primes: " << next_prime << " "; for(int i=0; i<20; i++) { pPrime->GetNextPrime(&next_prime); cout << next_prime << " "; } cout << "\n\n"; // Release all pPrimeFactory->Release(); pPrime->Release(); pBindCtx->Release(); pMoniker->Release(); cout << "Client: Calling CoUninitialize()" << endl; CoUninitialize(); }