client embed proxy.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. CoInitialize(NULL);
  9. // Code to avoid proxy-stub DLL
  10. IUnknown* pUnknown;
  11. DWORD dwUnused;
  12. DllGetClassObject(IID_ISum, IID_IUnknown, (void**)&pUnknown);
  13. CoRegisterClassObject(IID_ISum, pUnknown, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwUnused);
  14. CoRegisterPSClsid(IID_ISum, IID_ISum);
  15. ISum* pSum;
  16. cout << "Client: Calling CoCreateInstance() " << endl;
  17. CoCreateInstance(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnknown);
  18. cout << "Client: Calling QueryInterface() for ISum on " << pUnknown << endl;
  19. HRESULT hr = pUnknown->QueryInterface(IID_ISum, (void**)&pSum);
  20. if(FAILED(hr))
  21. cout << "QueryInterface FAILED" << endl;
  22. cout << "Client: Calling Release() for pUnknown" << endl;
  23. hr = pUnknown->Release();
  24. cout << "Client: pSum = " << pSum << endl;
  25. int sum;
  26. hr = pSum->Sum(4, 9, &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. }