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