client.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
源码类别:

Windows编程

开发平台:

Visual C++

  1. #define _WIN32_DCOM
  2. #include <iostream.h>
  3. #include "component with registrationcomponent.h" // Generated by MIDL
  4. // {10000002-0000-0000-0000-000000000001}
  5. const CLSID CLSID_InsideCOM = {0x10000002,0x0000,0x0000,
  6.     {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}};
  7. void main()
  8. {
  9.     IUnknown* pUnknown;
  10.     ISum* pSum;
  11.     HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
  12.     if(FAILED(hr))
  13.         cout << "CoInitializeEx failed. " << endl;
  14.     hr = CoCreateInstance(CLSID_InsideCOM, NULL, 
  15.         CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&pUnknown);
  16.     if(FAILED(hr))
  17.         cout << "CoCreateInstance failed. " << endl;
  18.     hr = pUnknown->QueryInterface(IID_ISum, (void**)&pSum);
  19.     if(FAILED(hr))
  20.         cout << "IID_ISum not supported. " << endl;
  21.     pUnknown->Release();
  22.     int sum;
  23.     hr = pSum->Sum(2, 3, &sum);
  24.     if(SUCCEEDED(hr))
  25.         cout << "Client: Calling Sum(2, 3) = " << sum << endl;
  26.     pSum->Release();
  27.     CoUninitialize();
  28. }