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. void main()
  7. {
  8. cout << "Client: Calling CoInitialize()" << endl;
  9. CoInitializeEx(NULL, COINIT_MULTITHREADED);
  10. ISum* pSum = 0;
  11. // cout << "Client: Calling CoCreateInstance() " << endl;
  12. // CoCreateInstance(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnknown);
  13. HRESULT hr = 0;
  14. COSERVERINFO csi = { 0, 0, 0, 0 };
  15. // csi.pwszName = L"RemoteMachineName";
  16. BIND_OPTS2 bopts;
  17. bopts.dwClassContext = CLSCTX_LOCAL_SERVER;
  18. bopts.cbStruct = sizeof(BIND_OPTS2);
  19. bopts.pServerInfo = &csi;
  20. // hr = CoGetObject(L"new:Component.InsideCOM", &bopts, IID_ISum, (void**)&pSum);
  21. hr = CoGetObject(L"new:10000002-0000-0000-0000-000000000001", &bopts, IID_ISum, (void**)&pSum);
  22. if(FAILED(hr))
  23. printf("hr = %0xn", hr);
  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. }