2014-05-03 1 views
1

Je viens d'intégrer un contrôle ActiveX IE/navigateur Web dans mon application C++ (MFC). Et je suis curieux comment puis-je obtenir la version de IE utilisée pour cela?Comment obtenir une version du contrôle IE ActiveX incorporé?

+0

démarrage IE à partir du bureau et utiliser l'aide + A propos. –

+0

@HansPassant: Très drôle. – c00000fd

+0

[Cette réponse] (http://stackoverflow.com/a/2897215/2065121) à une question connexe peut être utile. –

Répondre

0

Il s'agit en quelque sorte d'un hack, mais vous pouvez utiliser mshtml.dll qui est un integral part de n'importe quel contrôle IE et récupérer sa version. Vient ensuite l'extrait de code d'un de mes projets:

#define SIZEOF(f) (sizeof(f)/sizeof(f[0])) 

HMODULE hModMshtl = ::GetModuleHandle(L"mshtml.dll"); 
if(hModMshtl) 
{ 
    TCHAR buffMshtl[MAX_PATH]; 
    buffMshtl[0] = 0; 
    ::GetModuleFileName(hModMshtl, buffMshtl, SIZEOF(buffMshtl)); 
    buffMshtl[SIZEOF(buffMshtl) - 1] = 0; 

    CString strProdName; 
    VS_FIXEDFILEINFO vi; 
    if(GetFileVersionAndProductName(buffMshtl, &vi, &strProdName)) 
    { 
     //Got it 
     _tprintf(L"%s v.%d.%d.%d.%d", 
      strProdName.GetString(), 
      (DWORD)((vi.dwProductVersionLS & 0xFFFF0000) >> 16), 
      (DWORD)(vi.dwProductVersionLS & 0xFFFF), 
      (DWORD)((vi.dwProductVersionMS & 0xFFFF0000) >> 16), 
      (DWORD)(vi.dwProductVersionMS & 0xFFFF) 
      ); 
    } 
} 

et voici comment vous pouvez obtenir sa version:

BOOL GetFileVersionAndProductName(LPCTSTR pFilePath, VS_FIXEDFILEINFO* pOutVersionInfo, CString* pOutProductName) 
{ 
    BOOL bRes = FALSE; 
    CString strFilePath = pFilePath; 
    LPCTSTR pDescBuf = NULL; 

    struct LANGANDCODEPAGE { 
     WORD wLanguage; 
     WORD wCodePage; 
    }; 

    CString strProdName; 

    BYTE* pData = NULL; 
    if(!strFilePath.IsEmpty()) 
    { 
     //Get size needed 
     DWORD dwDummy; 
     DWORD dwSz = ::GetFileVersionInfoSize((LPTSTR)strFilePath.GetString(), &dwDummy); 
     if(dwSz > 0) 
     { 
      //Reserve mem 
      pData = new (std::nothrow)BYTE[dwSz]; 
      if(pData) 
      { 
       //Retrieve version info 
       if(::GetFileVersionInfo((LPTSTR)strFilePath.GetString(), NULL, dwSz, pData)) 
       { 
        UINT nczBufLn; 
        VS_FIXEDFILEINFO* pVi = NULL; 
        if(VerQueryValue(pData, _T("\\"), (VOID**)&pVi, &nczBufLn)) 
        { 
         if(pVi && 
          nczBufLn >= sizeof(*pVi) && 
          pVi->dwSignature == 0xFEEF04BD) 
         { 
          //Got it 
          bRes = TRUE; 

          if(pOutVersionInfo) 
           *pOutVersionInfo = *pVi; 
         } 
        } 


        struct LANGANDCODEPAGE 
        { 
         WORD wLanguage; 
         WORD wCodePage; 
        } *lpTranslate = NULL; 

        // Read the list of languages and code pages. 
        UINT cbTranslate; 
        if(VerQueryValue(pData, L"\\VarFileInfo\\Translation", (LPVOID*)&lpTranslate, &cbTranslate)) 
        { 
         //Get first language 
         if(lpTranslate && 
          cbTranslate >= sizeof(*lpTranslate)) 
         { 
          //Retrieve product name 
          CString strBlock; 
          strBlock.Format(L"\\StringFileInfo\\%04x%04x\\ProductName", 
           lpTranslate[0].wLanguage, 
           lpTranslate[0].wCodePage); 

          UINT dwProdLn = 0; 
          VOID* lpBufferName = NULL; 
          if(VerQueryValue(pData, strBlock, &lpBufferName, &dwProdLn)) 
          { 
           //Get name 
           memcpy(strProdName.GetBufferSetLength(dwProdLn), lpBufferName, dwProdLn * sizeof(TCHAR)); 
           strProdName.ReleaseBuffer(); 
          } 
         } 
        } 
       } 
      } 
     } 
    } 


    if(pOutProductName) 
     *pOutProductName = strProdName; 

    //Free mem 
    if(pData) 
     delete[] pData; 

    return bRes; 
} 
Questions connexes