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

Windows编程

开发平台:

Visual C++

  1. // client.cpp
  2. // This client program only works on Windows 95/98
  3. // To use this client under Windows 2000 or Windows NT, see the comments in the local.cpp file
  4. #define _WIN32_DCOM
  5. #include <iostream.h>
  6. #include "Componentcomponent.h"
  7. void main()
  8. {
  9. cout << "Client: Calling CoInitialize()" << endl;
  10. CoInitialize(NULL);
  11. IUnknown* pUnknown;
  12. ISum* pSum;
  13. cout << "Client: Calling CoCreateInstance() " << endl;
  14. CoCreateInstance(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnknown);
  15. cout << "Client: Calling QueryInterface() for ISum on " << pUnknown << endl;
  16. HRESULT hr = pUnknown->QueryInterface(IID_ISum, (void**)&pSum);
  17. if(FAILED(hr))
  18. cout << "QueryInterface FAILED" << endl;
  19. cout << "Client: Calling Release() for pUnknown" << endl;
  20. hr = pUnknown->Release();
  21. cout << "Client: pSum = " << pSum << endl;
  22. int sum;
  23. hr = pSum->Sum(2, 3, &sum);
  24. if(SUCCEEDED(hr))
  25. cout << "Client: Calling Sum() return value is " << sum << endl;
  26. hr = pSum->Sum(7, 8, &sum);
  27. if(SUCCEEDED(hr))
  28. cout << "Client: Calling Sum() return value is " << sum << endl;
  29. cout << "Client: Calling Release() for pSum" << endl;
  30. hr = pSum->Release();
  31. cout << "Client: Calling CoUninitialize()" << endl;
  32. CoUninitialize();
  33. }