client.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
- #define _WIN32_DCOM
- #include <windows.h>
- #include <stdio.h>
- #include <iostream.h>
- #include "Componentcomponent.h"
- 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:MyHost!clsid:10000013-0000-0000-0000-000000000001";
- HRESULT hr = MkParseDisplayName(pBindCtx, string, &eaten, &pMoniker);
- if(FAILED(hr))
- cout << "MkParseDisplayName failed" << endl;
- IPrimeFactory* pPrimeFactory;
- pMoniker->BindToObject(pBindCtx, NULL, IID_IPrimeFactory, (void**)&pPrimeFactory);
- IPrime* pPrime;
- pPrimeFactory->CreatePrime(11, &pPrime);
- int next;
- pPrime->GetNextPrime(&next);
- cout << next << endl;
- OLECHAR* moniker_name;
- pMoniker->GetDisplayName(pBindCtx, NULL, &moniker_name);
- wprintf(L"DisplayName is %sn", moniker_name);
- CoTaskMemFree(moniker_name);
- pPrime->Release();
- pPrimeFactory->Release();
- pBindCtx->Release();
- pMoniker->Release();
- CoUninitialize();
- }