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

Windows编程

开发平台:

Visual C++

  1. // client.cpp
  2. #define _WIN32_DCOM
  3. #include <iostream.h>
  4. #include "Containercontainer.h"
  5. const CLSID CLSID_Container = {0x10000012,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}};
  6. void main()
  7. {
  8. cout << "Client: Calling CoInitialize()" << endl;
  9. CoInitialize(NULL);
  10. IMultiply* pMultiply;
  11. cout << "Client: Calling CoCreateInstance() " << endl;
  12. CoCreateInstance(CLSID_Container, NULL, CLSCTX_INPROC_SERVER, IID_IMultiply, (void**)&pMultiply);
  13. cout << "Client: pMultiply = " << pMultiply << endl;
  14. HRESULT hr;
  15. int multiply;
  16. hr = pMultiply->Multiply(4, 3, &multiply);
  17. if(SUCCEEDED(hr))
  18. cout << "Client: Calling Multiply() return value is " << multiply << endl;
  19. ISum* pSum;
  20. pMultiply->QueryInterface(IID_ISum, (void**)&pSum);
  21. int sum;
  22. hr = pSum->Sum(4, 3, &sum);
  23. if(SUCCEEDED(hr))
  24. cout << "Client: Calling Sum() return value is " << sum << endl;
  25. cout << "Client: Calling Release() for pMultiply" << endl;
  26. hr = pMultiply->Release();
  27. hr = pSum->Release();
  28. cout << "Client: Calling CoUninitialize()" << endl;
  29. CoUninitialize();
  30. }