#define _WIN32_DCOM #include #include #include #include "Component\component.h" using namespace std; void main() { CoInitialize(NULL); IBindCtx* pBindCtx; CreateBindCtx(0, &pBindCtx); ULONG eaten; IMoniker* pMoniker; // Replace MyHost with machine name on which the component is registered // OLECHAR string[] = L"host:localhost!clsid:10000013-0000-0000-0000-000000000001"; // OLECHAR string[] = L"host:127.0.0.1!clsid:10000013-0000-0000-0000-000000000001"; OLECHAR string[] = L"clsid:10000013-0000-0000-0000-000000000001"; HRESULT hr = MkParseDisplayName(pBindCtx, string, &eaten, &pMoniker); if(FAILED(hr)) { cout << "MkParseDisplayName failed" << endl; return; } IPrimeFactory* pPrimeFactory; pMoniker->BindToObject(pBindCtx, NULL, IID_IPrimeFactory, (void**)&pPrimeFactory); IPrime* pPrime; pPrimeFactory->CreatePrime(1, &pPrime); int next; for(int i=0; i<10; i++) { pPrime->GetNextPrime(&next); cout << next << endl; } OLECHAR* moniker_name; pMoniker->GetDisplayName(pBindCtx, NULL, &moniker_name); wprintf(L"DisplayName is %s\n", moniker_name); CoTaskMemFree(moniker_name); pPrime->Release(); pPrimeFactory->Release(); pBindCtx->Release(); pMoniker->Release(); CoUninitialize(); }