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

Windows编程

开发平台:

Visual C++

  1. // CoGetClassObject Client.cpp
  2. // Use this client on Windows 2000 or Windows NT
  3. #define _WIN32_DCOM
  4. #include <iostream.h>
  5. #include "Componentcomponent.h"
  6. void main()
  7. {
  8. cout << "Client: Calling CoInitialize()" << endl;
  9. CoInitialize(NULL);
  10. HRESULT hr;
  11. ISum* pSum;
  12. IClassFactory* pClassFactory;
  13. cout << "Client: Calling CoGetClassObject()" << endl;
  14. hr = CoGetClassObject(CLSID_InsideCOM, CLSCTX_LOCAL_SERVER, NULL, IID_IClassFactory, (void**)&pClassFactory);
  15. if(FAILED(hr))
  16. cout << "CoGetClassObject FAILED" << endl;
  17. cout << "Client: Calling CreateInstace() pClassFactory = " << pClassFactory << endl;
  18. hr = pClassFactory->CreateInstance(NULL, IID_ISum, (void**)&pSum);
  19. if(FAILED(hr))
  20. cout << "CreateInstance FAILED" << endl;
  21. cout << "Client: Calling Release()" << endl;
  22. pClassFactory->Release();
  23. int sum;
  24. hr = pSum->Sum(2, 3, &sum);
  25. if(SUCCEEDED(hr))
  26. cout << "Client: Calling Sum() on " << pSum << " return value is " << sum << endl;
  27. hr = pSum->Sum(7, 8, &sum);
  28. if(SUCCEEDED(hr))
  29. cout << "Client: Calling Sum() on " << pSum << " return value is " << sum << endl;
  30. hr = pSum->Release();
  31. cout << "Client: Calling Release() for ISum on " << hr << endl;
  32. cout << "Client: Calling CoUninitialize()" << endl;
  33. CoUninitialize();
  34. }