client.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
- // client.cpp
- #define _WIN32_DCOM
- #include <iostream.h>
- #include "Componentcomponent.h"
- void main()
- {
- 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
- IPrimeFactory* pPrimeFactory;
- pMoniker->BindToObject(pBindCtx, NULL, IID_IPrimeFactory, (void**)&pPrimeFactory);
- // Use the custom class object to create a Prime object
- IPrime* pPrime;
- pPrimeFactory->CreatePrime(7, &pPrime);
- // Now we have a Prime object
- int next_prime;
- pPrime->GetNextPrime(&next_prime);
- cout << next_prime << endl; // Displays 11
- // Release all
- pPrimeFactory->Release();
- pPrime->Release();
- pBindCtx->Release();
- pMoniker->Release();
- cout << "Client: Calling CoUninitialize()" << endl;
- CoUninitialize();
- }