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. HRESULT hr;
  8. cout << "Client: Calling CoInitialize()" << endl;
  9. CoInitializeEx(NULL, COINIT_MULTITHREADED);
  10. ISum* pSum = 0;
  11. hr = CoCreateInstance(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, IID_ISum, (void**)&pSum);
  12. if(FAILED(hr))
  13. {
  14. cout << "CoCreateInstance FAILED" << endl;
  15. return;
  16. }
  17. cout << "Client:Calling pSum->Sum" << endl;
  18. int sum;
  19. pSum->Sum(4, 5, &sum);
  20. cout << "Client: Sum 4 + 5 = " << sum << endl;
  21. pSum->Sum(73, 15, &sum);
  22. cout << "Client: Sum 73 + 15 = " << sum << endl;
  23. pSum->Sum(24, 35, &sum);
  24. cout << "Client: Sum 24 + 35 = " << sum << endl;
  25. pSum->Release();
  26. CoUninitialize();
  27. }