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 "Componentcomponent.h"
  6. #include "ChannelHookchannelhook.h"
  7. void main()
  8. {
  9. cout << "Client: Calling CoInitialize()" << endl;
  10. CoInitialize(NULL);
  11. // Load the channel hook
  12. void* silly;
  13. CoCreateInstance(CLSID_ClientChannelHook, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, &silly);
  14. /*
  15. To connect to the Component on the local machine use:
  16.    COSERVERINFO ServerInfo = { 0, 0, 0, 0 };
  17. To connect to the Component on a remote machine use:
  18.    COSERVERINFO ServerInfo = { 0, L"YourServerName", 0, 0 };
  19. */
  20. COSERVERINFO ServerInfo = { 0, 0, 0, 0 };
  21. cout << "Client: Calling CoCreateInstance() " << endl;
  22. MULTI_QI qi = { &IID_IUnknown, NULL, 0 };
  23. HRESULT hr = CoCreateInstanceEx(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, &ServerInfo, 1, &qi);
  24. if(FAILED(hr))
  25. {
  26. printf("Client: hr = %0xn", hr);
  27. exit(0);
  28. }
  29. ISum* pSum;
  30. qi.pItf->QueryInterface(IID_ISum, (void**)&pSum);
  31. int sum;
  32. hr = pSum->Sum(4, 9, &sum);
  33. cout << "Client: Calling Sum() return value is " << sum << endl;
  34. printf("HRESULT is %xn", hr);
  35. cout << "Client: Calling Release() for pSum" << endl;
  36. hr = pSum->Release();
  37. cout << "Client: Calling CoUninitialize()" << endl;
  38. qi.pItf->Release();
  39. CoUninitialize();
  40. }