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

Windows编程

开发平台:

Visual C++

  1. // client.cpp
  2. #define _WIN32_DCOM
  3. #include <iostream.h>
  4. #include "Componentcomponent.h"
  5. void main()
  6. {
  7. cout << "Client: Calling CoInitialize()" << endl;
  8. CoInitializeEx(NULL, COINIT_MULTITHREADED);
  9. IUnknown* pUnknown;
  10. ISum* pSum;
  11. cout << "Client: Calling CoCreateInstance() " << endl;
  12. CoCreateInstance(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnknown);
  13. cout << "Client: Calling QueryInterface() for ISum on " << pUnknown << endl;
  14. HRESULT hr = pUnknown->QueryInterface(IID_ISum, (void**)&pSum);
  15. if(FAILED(hr))
  16. cout << "QueryInterface FAILED" << endl;
  17. cout << "Client: Calling Release() for pUnknown" << endl;
  18. hr = pUnknown->Release();
  19. MYTYPE sum[3];
  20. sum[0].a = 1;
  21. sum[0].b = 5;
  22. sum[1].a = 2;
  23. sum[1].b = 4;
  24. sum[2].a = 3;
  25. sum[2].b = 3;
  26. hr = pSum->Sum(3, sum);
  27. if(SUCCEEDED(hr))
  28. cout << "Client: Calling Sum() return value is" << endl;
  29. cout << "Client: Calling Release() for pSum" << endl;
  30. hr = pSum->Release();
  31. cout << "Client: Calling CoUninitialize()" << endl;
  32. CoUninitialize();
  33. }