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

Windows编程

开发平台:

Visual C++

  1. #define _WIN32_DCOM
  2. #include <windows.h>
  3. #include <iostream.h>
  4. #include <stdio.h>
  5. CLSID CLSID_TypeFactory = {0xB5866878, 0xBD99, 0x11D0, 0xB0, 0x4B, 0x00, 0xC0, 0x4F, 0xD9, 0x15, 0x50};
  6. void main()
  7. {
  8. HRESULT hr = 0;
  9. hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
  10. ITypeLib* pTypeLib = 0;
  11. GUID LIBID_Component = {0x10000003, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
  12.     hr = LoadRegTypeLib(LIBID_Component, 1, 0, LANG_NEUTRAL, &pTypeLib);
  13. ITypeInfo* pTypeInfo = 0;
  14. IID IID_ISum = {0x10000001, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
  15.     hr = pTypeLib->GetTypeInfoOfGuid(IID_ISum, &pTypeInfo);
  16. printf("hr = %0xn", hr);
  17. ITypeFactory* pTypeFactory = 0;
  18. hr = CoGetClassObject(CLSID_TypeFactory, CLSCTX_INPROC_SERVER, 0, IID_ITypeFactory, (void**)&pTypeFactory);
  19. printf("hr = %0xn", hr);
  20. IUnknown* pUnknown = 0;
  21. hr = pTypeFactory->CreateFromTypeInfo(pTypeInfo, IID_IUnknown, &pUnknown);
  22. printf("hr = %0xn", hr);
  23. ITypeMarshal* pTypeMarshal = 0;
  24. hr = pUnknown->QueryInterface(IID_ITypeMarshal, (void**)&pTypeMarshal);
  25. printf("hr = %0xn", hr);
  26. IMarshal* pMarshal = 0;
  27. hr = pTypeMarshal->QueryInterface(IID_IMarshal, (void**)&pMarshal);
  28. printf("hr = %0xn", hr);
  29. // pTypeMarshal->
  30. //  pMarshal->
  31. pMarshal->Release();
  32. pTypeMarshal->Release();
  33. pUnknown->Release();
  34. pTypeFactory->Release();
  35. CoUninitialize();
  36. }