我用PowerBuilder编译生成的一个可执行程序,
用GetFileVersionInfoSize,GetFileVersionInfo能得到它的版本信息,
用VerQueryValue(m_lpBuffer, 
              TEXT("\\VarFileInfo\\Translation"),……)显示其中的语言字符集为"04091252",
用VerQueryValue(m_lpBuffer,"\\StringFileInfo\\……)时却返回0我的算法代码为: m_dwHandle = 0;
m_uiDataSize = 80;
int nRet;
m_lpData = malloc(m_uiDataSize);
// Get the version information block size,
// then use it to allocate a storage buffer.
m_dwSize = ::GetFileVersionInfoSize(m_lpszImageName, &m_dwHandle);
if(!m_dwSize)
{
AfxMessageBox("调用GetFileVersionInfoSize出错");
return ;
}
m_lpBuffer = malloc(m_dwSize);
// Get the versioninformation block
nRet=::GetFileVersionInfo(m_lpszImageName, 0, m_dwSize, m_lpBuffer);
if(!nRet)
{
AfxMessageBox("调用GetFileVersionInfo出错");
return ;
} int i;
UINT nLen;
memset(m_szLangCodePage,0,1024);
VerQueryValue(m_lpBuffer, 
              TEXT("\\VarFileInfo\\Translation"),
              (LPVOID*)&lpTranslate,
              &nLen);
// Read the file description for each language and code page.
int nLoop;
nLoop=((nLen)/sizeof(struct LANGANDCODEPAGE));
char szTmp[2048];
for( i=0; i < nLoop; i++ )
{
wsprintf(m_szLangCodePage, 
TEXT("%04x%04x"),
lpTranslate[i].wLanguage,
lpTranslate[i].wCodePage);
  break;//如果有多个语言字符集,则应该继续
 
}//读取公司信息
CStringstrCompany;
m_lpData=NULL;
char szTmp[2048];
strcpy(szTmp,"\\StringFileInfo\\");
strcat(szTmp,m_szLangCodePage);
strcat(szTmp,"\\CompanyName");
int nRet;
nRet=::VerQueryValue(m_lpBuffer,
            szTmp,
&m_lpData,
&m_uiDataSize);
if(!nRet)  //此处 nRet=0 ?
return "";
strCompany.Format("%s", m_lpData);
m_lpData=NULL;
return strCompany;
;

解决方案 »

  1.   

    后来我咨询了一下sybase公司,得知要将语言字符集设置为 040904e4 ,并参考下列代码IF VerQueryValue(lc_verinfo, "\\VarFileInfo\\Translation", ll_strAddress, li_length) THEN
      IF (li_length >= 4) THEN
         // ll_strAddress contains a pointer to a string, so use the address format to resolve the 
         // pointer.  Since the string may contain null bytes, and PowerBuilder using a null terminated
         // string paradigm, we increment the char pointer to retrieve each of the four bytes in the 
         // language/code page sequence
         lc_cp[1] = String(ll_strAddress,   "address")
         lc_cp[2] = String(ll_strAddress+1, "address")
         lc_cp[3] = String(ll_strAddress+2, "address")
         lc_cp[4] = String(ll_strAddress+3, "address")
         // convert the language / codepage to a string for a subquent lookup.  There are two methods
         // here, one for PB-created executables and one for other third-party executables.  CR 257065
         // has been opened to remedy the non-standard way that PowerBuilder stores this information.
         IF this.getIsPBApp() THEN  //要人工设置一个参数标志为PB的exe
            ls_langString = int2Hex(ASC(lc_cp[2]), 2) + int2Hex(ASC(lc_cp[1]), 2) &
               + int2Hex(Integer(int2Hex(ASC(lc_cp[4]), 2) + int2Hex(ASC(lc_cp[3]), 2)) , 4)
         ELSE
              ls_langString = int2Hex(ASC(lc_cp[2]), 2) + int2Hex(ASC(lc_cp[1]), 2) &
               + int2Hex(ASC(lc_cp[4]), 2) + int2Hex(ASC(lc_cp[3]), 2)
         END IF
       ELSE
         RETURN is_null
       END IF
    ELSE
      RETURN is_null
    END IF他的算法是:
    将得到的language code page 转换为对应的16进制串04091252,
    再将后4位"1252"做为10进制串,再转换为16进制.
    这是什么算法啊?
      

  2.   

    这个问题好像和PB关系不大.在windows中右击PB生成的EXE,显示属性中却正常显示各个版本信息.而我的程序对许多VC++,VB,delphi的编译生成的程序都能正常显示版本信息.??????