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

Windows编程

开发平台:

Visual C++

  1. // client.cpp
  2. #define _WIN32_DCOM
  3. #include <windows.h>
  4. #include <iostream.h>
  5. #include <stdio.h>
  6. #include "component.h"
  7. const CLSID CLSID_JavaComponent = { 0x2652CA66, 0xD6CF, 0x11D2, { 0xBB, 0x51, 0x00, 0x60, 0x97, 0xB5, 0xEA, 0xFC } };
  8. void main()
  9. {
  10. cout << "Client: Calling CoInitialize()" << endl;
  11. CoInitializeEx(NULL, COINIT_MULTITHREADED);
  12. HRESULT hr;
  13. ISum* pSum;
  14. cout << "Client: Calling CoCreateInstance() " << endl;
  15. hr = CoCreateInstance(CLSID_JavaComponent, NULL, CLSCTX_INPROC_SERVER, IID_ISum, (void**)&pSum);
  16. if(FAILED(hr))
  17. cout << "FAILED" << endl;
  18. long sum;
  19. hr = pSum->Sum(5, 3, &sum);
  20. if(SUCCEEDED(hr))
  21. cout << "Sum = " << sum << endl;
  22. else
  23. cout << "Sum FAILED" << endl;
  24. hr = pSum->Sum(-2, 3, &sum);
  25. if(SUCCEEDED(hr))
  26. cout << "Sum = " << sum << endl;
  27. else
  28. {
  29. cout << "Sum FAILED" << endl;
  30. ISupportErrorInfo* pSupportErrorInfo;
  31. if(SUCCEEDED(pSum->QueryInterface(IID_ISupportErrorInfo, (void**)&pSupportErrorInfo)))
  32. {
  33. if(pSupportErrorInfo->InterfaceSupportsErrorInfo(IID_ISum) == S_OK)
  34. {
  35. IErrorInfo* pErrorInfo;
  36. GetErrorInfo(0, &pErrorInfo);
  37. BSTR description;
  38. pErrorInfo->GetDescription(&description);
  39. wprintf(L"HRESULT = %x, Description: %sn", hr, description);
  40. SysFreeString(description);
  41. pErrorInfo->Release();
  42. }
  43. pSupportErrorInfo->Release();
  44. }
  45. }
  46. cout << "Client: Calling Release() for pSum" << endl;
  47. pSum->Release();
  48. cout << "Client: Calling CoUninitialize()" << endl;
  49. CoUninitialize();
  50. }