您的位置:首页 > 产品设计 > UI/UE

(转)如何解释 InternetQueryOption的INTERNET_VERSION_INFO 结构的结果

2012-03-16 15:55 225 查看
您可以使用 InternetQueryOption 函数检索
WinInet DLL 的版本。返回的版本信息不是版本标记 WinInet.dll 文件的 DLL 的内部版本号。

您可以使用 INTERNET_VERSION_INFO 结构 (省略检查代码错误)
如下:


INTERNET_VERSION_INFO structVI;
DWORD dwStructSize = sizeof(INTERNET_VERSION_INFO);
InternetQueryOption (NULL, INTERNET_OPTION_VERSION,
(LPVOID)&structVI, &dwStructSize);
printf("WinINet Major Version: %d\n", structVI.dwMajorVersion);
printf("WinINet Minor Version: %d\n", structVI.dwMinorVersion);


的平台 SDK 包含 INTERNET_OPTION_VERSION 标志可用于与 InternetQueryOption 函数的下列说明:

检索一个 INTERNET_VERSION_INFO 结构,它包含 Wininet.dll 的版本号。可以使用此选项通过 InternetQueryOption NULL HINTERNET 句柄。
此函数调用返回 INTERNET_VERSION_INFO 结构可以解释如下: 

dwMajorVersiondwMinorVersionWinInet 版本
10Internet 3 Explorer
11Internet 4 Explorer
12Internet 5 Explorer
可以通过使用版本的 api,如下所示获得精确的 Wininet.dll 版本信息 (如文件属性中所示):

#define SWAPWORDS(X) ( (X<<16) | (X>>16) )

...

if (! (dwSize = GetFileVersionInfoSize (TEXT("wininet.dll"), &dwHandle) ) )

{

    dwError = GetLastError();

    if (dwError == 2)

       // 2 is file no found error

       cerr << "Wininet.dll is not found" << endl;

    else if (dwError == 1812)<BR/>

       // 1812 means no resource section information, very unlikely case

       cerr << "Wininet.dll does contain resource section" << endl;

    else

       cerr << "GetFileVersionInfoSize failed: " << 

       GetLastError() << endl;

       return 0;

}

lpBuffer = new TCHAR [dwSize]; 

if (!GetFileVersionInfo (TEXT ("wininet.dll"), 0, 

     dwSize, (LPVOID) lpBuffer) )

{

   cerr << "GetFileVersionInfo failed: " 

   << GetLastError() << endl;

   return 0;

}

LPDWORD lpdwLangCp;

if (!VerQueryValue(lpBuffer, TEXT("\\VarFileInfo\\Translation"), 

     (LPVOID*) &lpdwLangCp, &dwUint) ) 

{

   cerr << "VerQueryValue failed: " << GetLastError() << endl;

   return 0;

}

TCHAR     szLangCp[9];

wsprintf( szLangCp, TEXT ("%08X"),SWAPWORDS( *lpdwLangCp ));

TCHAR SubBlock [2048];

wsprintf( SubBlock, TEXT("\\StringFileInfo\\%s\\FileVersion"), szLangCp );

if (!VerQueryValue(lpBuffer, SubBlock,  (LPVOID*)&Buffer, &dwUint) ) 

{

   cerr << "No file version info available" << endl;

   return 0;

}

else

  cout << "File Version: " << Buffer << endl;

wsprintf( SubBlock, TEXT("\\StringFileInfo\\%s\\ProductVersion"), 

          szLangCp );

if (!VerQueryValue(lpBuffer, SubBlock,  (LPVOID*)&Buffer, &dwUint) ) 

{

   cerr << "No produce version info available" << endl;

   return 0;

}

else

   cout << "Product Version: " << Buffer << endl;

wsprintf( SubBlock, TEXT("\\StringFileInfo\\%s\\FileDescription"), 

        szLangCp );

if (!VerQueryValue(lpBuffer, SubBlock,  (LPVOID*)&Buffer, &dwUint) ) 

{

   cerr << "No File Description info available" << endl;

   return 0;

}

else

   cout << "File Description: " << Buffer << endl;

delete [] lpBuffer;

转自:http://support.microsoft.com/kb/244857/zh-cn
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐