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

Windows编程

开发平台:

Visual C++

  1. // client.cpp
  2. #define _WIN32_DCOM
  3. #include <iostream.h>
  4. #include <stdio.h>
  5. #include "Component CoInitializeSecuritycomponent.h"
  6. void main()
  7. {
  8. cout << "Client: Calling CoInitialize()" << endl;
  9. CoInitialize(NULL);
  10. IUnknown* pUnknown;
  11. ISum* pSum;
  12. cout << "Client: Calling CoCreateInstance() " << endl;
  13. HRESULT hr = CoCreateInstance(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnknown);
  14. if(FAILED(hr))
  15. {
  16. if(hr == E_ACCESSDENIED)
  17. printf("CoCreateInstance FAILED hr = E_ACCESSDENTIEDn", hr);
  18. else
  19. printf("CoCreateInstance FAILED hr = %0xn", hr);
  20. exit(0);
  21. }
  22. cout << "Client: Calling QueryInterface() for ISum on " << pUnknown << endl;
  23. hr = pUnknown->QueryInterface(IID_ISum, (void**)&pSum);
  24. if(FAILED(hr))
  25. cout << "QueryInterface FAILED" << endl;
  26. cout << "Client: Calling Release() for pUnknown" << endl;
  27. hr = pUnknown->Release();
  28. cout << "Client: pSum = " << pSum << endl;
  29. int sum;
  30. hr = pSum->Sum(4, 9, &sum);
  31. if(SUCCEEDED(hr))
  32. cout << "Client: Calling Sum() return value is " << sum << endl;
  33. cout << "Client: Calling Release() for pSum" << endl;
  34. hr = pSum->Release();
  35. cout << "Client: Calling CoUninitialize()" << endl;
  36. CoUninitialize();
  37. }