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

Windows编程

开发平台:

Visual C++

  1. // client.cpp
  2. #include <iostream.h>
  3. #include "Componentcomponent.h" // Generated by MIDL
  4. void main()
  5. {
  6. cout << "Client: Calling CoInitialize()" << endl;
  7. HRESULT hr = CoInitialize(NULL);
  8. if(FAILED(hr))
  9. cout << "CoInitialize failed" << endl;
  10. IUnknown* pUnknown;
  11. ISum* pSum;
  12. cout << "Client: Calling CoCreateInstance()" << endl;
  13. hr = CoCreateInstance(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnknown);
  14. if(FAILED(hr))
  15. cout << "CoCreateInstance failed" << endl;
  16. cout << "Client: Calling QueryInterface() for ISum on " << pUnknown << endl;
  17. hr = pUnknown->QueryInterface(IID_ISum, (void**)&pSum);
  18. if(FAILED(hr))
  19. cout << "IID_ISum not supported" << endl;
  20. hr = pUnknown->Release();
  21. cout << "Client: Calling pUnknown->Release() reference count = " << hr << endl;
  22. int sum;
  23. hr = pSum->Sum(2, 3, &sum);
  24. if(SUCCEEDED(hr))
  25. cout << "Client: Calling Sum(2, 3) = " << sum << endl;
  26. hr = pSum->Release();
  27. cout << "Client: Calling pSum->Release() reference count = " << hr << endl;
  28. cout << "Client: Calling CoUninitialize()" << endl;
  29. CoUninitialize();
  30. }