client.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. // Always need a bind context
  10. IBindCtx* pBindCtx;
  11. CreateBindCtx(0, &pBindCtx);
  12. // Convert the string to a moniker
  13. ULONG eaten;
  14. IMoniker* pMoniker;
  15. OLECHAR string[] = L"clsid:10000013-0000-0000-0000-000000000001";
  16. MkParseDisplayName(pBindCtx, string, &eaten, &pMoniker);
  17. // Bind the moniker to the named object
  18. IPrimeFactory* pPrimeFactory;
  19. pMoniker->BindToObject(pBindCtx, NULL, IID_IPrimeFactory, (void**)&pPrimeFactory);
  20. // Use the custom class object to create a Prime object
  21. IPrime* pPrime;
  22. pPrimeFactory->CreatePrime(7, &pPrime);
  23. // Now we have a Prime object
  24. int next_prime;
  25. pPrime->GetNextPrime(&next_prime);
  26. cout << next_prime << endl; // Displays 11
  27. // Release all
  28. pPrimeFactory->Release();
  29. pPrime->Release();
  30. pBindCtx->Release();
  31. pMoniker->Release();
  32. cout << "Client: Calling CoUninitialize()" << endl;
  33. CoUninitialize();
  34. }