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

Windows编程

开发平台:

Visual C++

  1. #define _WIN32_DCOM
  2. #include <windows.h>
  3. #include <iostream.h>
  4. #include <stdio.h>
  5. void main()
  6. {
  7. HRESULT hr = 0;
  8. CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
  9.     ITypeLib* pTypeLib = 0;
  10. GUID LIBID_Component = {0x10000003,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}};
  11.     LoadRegTypeLib(LIBID_Component, 1, 0, LANG_NEUTRAL, &pTypeLib);
  12. TLIBATTR* r = 0;
  13. pTypeLib->GetLibAttr(&r);
  14. OLECHAR string[255];
  15. StringFromGUID2(r->guid, string, 255);
  16. wprintf(L"LIBID = %sn", string);
  17. if(r->syskind == SYS_WIN32)
  18. cout << "syskind = SYS_WIN32" << endl;
  19. switch(r->wLibFlags)
  20. {
  21. case LIBFLAG_FRESTRICTED:
  22. cout << "wLibFlags = LIBFLAG_FRESTRICTED" << endl;
  23. break;
  24. case LIBFLAG_FCONTROL:
  25. cout << "wLibFlags = LIBFLAG_FCONTROL" << endl;
  26. break;
  27. case LIBFLAG_FHIDDEN:
  28. cout << "wLibFlags = LIBFLAG_FHIDDEN" << endl;
  29. break;
  30. }
  31. cout << "Version major = " << r->wMajorVerNum << " minor = " << r->wMinorVerNum << endl;
  32. cout << "Locale ID = " << r->lcid << endl;
  33. pTypeLib->ReleaseTLibAttr(r);
  34. CLSID CLSID_InsideCOM = {0x10000002,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}};
  35. ITypeInfo* pTypeInfo = 0;
  36. IID IID_ISum = {0x10000001,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}};
  37.     hr = pTypeLib->GetTypeInfoOfGuid(IID_ISum, &pTypeInfo);
  38. cout << "Method ISum::Sum" << endl;
  39. FUNCDESC* pFuncDesc = 0;
  40. hr = pTypeInfo->GetFuncDesc(0, &pFuncDesc);
  41. cout << "memid = " << pFuncDesc->memid << endl;
  42. cout << pFuncDesc->cParams << " parameters" << endl;
  43. pTypeInfo->ReleaseFuncDesc(pFuncDesc);
  44. pTypeInfo->Release();
  45.     pTypeLib->Release();
  46. CoUninitialize();
  47. }