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. CoInitialize(NULL);
  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. cout << "Client: pSum = " << pSum << endl;
  20. int sum;
  21. hr = pSum->Sum(4, 9, &sum);
  22. if(SUCCEEDED(hr))
  23. cout << "Client: Calling Sum() return value is " << sum << endl;
  24. cout << "Client: Calling Release() for pSum" << endl;
  25. hr = pSum->Release();
  26. cout << "Client: Calling CoUninitialize()" << endl;
  27. CoUninitialize();
  28. }