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. DaysOfTheWeek day = Thursday;
  20. hr = pSum->Test(day);
  21. if(SUCCEEDED(hr))
  22. cout << "Client: Calling Sum() return value is" << endl;
  23. cout << "Client: Calling Release() for pSum" << endl;
  24. hr = pSum->Release();
  25. cout << "Client: Calling CoUninitialize()" << endl;
  26. CoUninitialize();
  27. }