client.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
- #define _WIN32_DCOM
- #include <iostream.h>
- #include "component with registrationcomponent.h" // Generated by MIDL
- // {10000002-0000-0000-0000-000000000001}
- const CLSID CLSID_InsideCOM = {0x10000002,0x0000,0x0000,
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}};
- void main()
- {
- IUnknown* pUnknown;
- ISum* pSum;
- HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
- if(FAILED(hr))
- cout << "CoInitializeEx failed. " << endl;
- hr = CoCreateInstance(CLSID_InsideCOM, NULL,
- CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&pUnknown);
- if(FAILED(hr))
- cout << "CoCreateInstance failed. " << endl;
- hr = pUnknown->QueryInterface(IID_ISum, (void**)&pSum);
- if(FAILED(hr))
- cout << "IID_ISum not supported. " << endl;
- pUnknown->Release();
- int sum;
- hr = pSum->Sum(2, 3, &sum);
- if(SUCCEEDED(hr))
- cout << "Client: Calling Sum(2, 3) = " << sum << endl;
- pSum->Release();
- CoUninitialize();
- }