ENGLISH page is here.
GET DinopSearchBar
サイト内検索:
HOME
VC++ TIPS
ダウンロード
DinopExifReader
DinopSearchBar
DinopSearchBar mini
DinopTabbingBar
for Firefox
大阪湾の生き物
甲子園浜の自然
甲子園浜の干潟
甲子園浜の水中
甲子園浜の野鳥
近畿の山々
植物図鑑
箕面マップ
水中機材
カメラ
ランキング
望遠鏡の世界
顕微鏡の世界
Googleのすべて
GoogleマップAPI
ニュース
読んだ本
日記
変な料理の作り方
遺伝子操作
論文紹介
デイトレード
自動売買でFX
ネットで小遣い稼ぎ
Solaris
電子工作
その他
問い合わせ
VC++用コード集
大阪湾の生き物
水中用機材
since:2000/11/15
dinopcom@gmail.com
www.dinop.comは
だいのっぷ・どっと・こむ
と読んでください。







« シーフード皿うどん | メイン | 神戸の大蔵海岸(2006年9月22日) »

バージョンリソース文字列の取得




解説


 EXEファイルなどに格納されているバージョンリソースからデータを取り出すための クラス。
 複数言語のバージョンリソースが格納されている場合は、もっとも先に見つかった言語 のものを返す。本当なら日本語、ニュートラル、英語...の順序で検索したほうがいい のかもしれない...



使用例


	CAtlString		strData;
	CDnpFileVersion	cInfo;

	cInfo.Load("C:\\WINDOWS\\system32\\cmd.exe");
	cInfo.GetValue("FileDescription",strData);

	cInfo.GetComments(strData);
	cInfo.GetInternalName(strData);
	cInfo.GetProductName(strData);
	cInfo.GetCompanyName(strData);
	cInfo.GetLegalCopyright(strData);
	cInfo.GetProductVersion(strData);
	cInfo.GetFileDescription(strData);
	cInfo.GetLegalTrademarks(strData);
	cInfo.GetPrivateBuild(strData);
	cInfo.GetFileVersion(strData);
	cInfo.GetOriginalFilename(strData);
	cInfo.GetSpecialBuild(strData);




ソースコード



#include "atlstr.h"
#pragma	comment(lib,"Version.lib")

class	CDnpFileVersion
{
	struct LANGANDCODEPAGE
	{
	  WORD wLanguage;
	  WORD wCodePage;
	};


	BYTE*				_pVersionInfo;
	LANGANDCODEPAGE*	_pTranslation;
	UINT				_nTranslationLen;

	void	Destroy(void)
	{
		if(_pVersionInfo)
			delete	_pVersionInfo;
		_pVersionInfo = NULL;
		_pTranslation = NULL;
		_nTranslationLen = 0;
	}

public:
	CDnpFileVersion()
	{
		_pVersionInfo = NULL;
		_pTranslation = NULL;
		_nTranslationLen = 0;
	}

	~CDnpFileVersion()
	{
		Destroy();
	}


	bool	Load(LPCTSTR pszFile)
	{
		BOOL	ret;
		DWORD	dwSize;
		BYTE*	pData;
		BYTE*	pResult;
		UINT	nLen;

		Destroy();
		dwSize = ::GetFileVersionInfoSize(pszFile,NULL);
		if(dwSize == 0)
			return	false;

		pData = new BYTE[dwSize];
		if(pData == NULL)
			return	false;

		ret = ::GetFileVersionInfo(pszFile,NULL,dwSize,pData);

		if(ret)
			ret = ::VerQueryValue(pData,_T("\\VarFileInfo\\Translation"),(void**)&pResult,&nLen); 

		if(ret == FALSE)
		{
			delete	pData;
			return	false;
		}

		_pVersionInfo = pData;
		_pTranslation = (LANGANDCODEPAGE*)pResult;
		_nTranslationLen = nLen;

		return	true;
	}

	bool	Unload(void)
	{
		Destroy();
		return	true;
	}


	bool	GetValue(LPCTSTR pszBlockName,CAtlString& strValue)
	{
		int			i;
		int			nSize;
		BOOL		ret;
		UINT		nLen;
		BYTE*		pData;
		CAtlString	strPath;

		strValue = _T("");

		if(_pVersionInfo == NULL || _pTranslation == NULL)
			return	false;

		nSize = _nTranslationLen / sizeof(LANGANDCODEPAGE);

		for(i = 0; i < nSize; i++)
		{
			strPath.Format(_T("\\StringFileInfo\\%04x%04x\\%s"),_pTranslation[i].wLanguage,_pTranslation[i].wCodePage,pszBlockName);
			ret = ::VerQueryValue(_pVersionInfo,(LPTSTR)(LPCTSTR)strPath,(void**)&pData,&nLen);
			if(ret == FALSE)
				continue;

			strValue = (TCHAR*)pData;
			return	true;
		}

		return	false;
	}


	bool	GetComments(CAtlString& strValue)
	{
		return	GetValue(_T("Comments"),strValue);
	}

	bool	GetInternalName(CAtlString& strValue)
	{
		return	GetValue(_T("InternalName"),strValue);
	}

	bool	GetProductName(CAtlString& strValue)
	{
		return	GetValue(_T("ProductName"),strValue);
	}

	bool	GetCompanyName(CAtlString& strValue)
	{
		return	GetValue(_T("CompanyName"),strValue);
	}

	bool	GetLegalCopyright(CAtlString& strValue)
	{
		return	GetValue(_T("LegalCopyright"),strValue);
	}

	bool	GetProductVersion(CAtlString& strValue)
	{
		return	GetValue(_T("ProductVersion"),strValue);
	}

	bool	GetFileDescription(CAtlString& strValue)
	{
		return	GetValue(_T("FileDescription"),strValue);
	}

	bool	GetLegalTrademarks(CAtlString& strValue)
	{
		return	GetValue(_T("LegalTrademarks"),strValue);
	}

	bool	GetPrivateBuild(CAtlString& strValue)
	{
		return	GetValue(_T("PrivateBuild"),strValue);
	}

	bool	GetFileVersion(CAtlString& strValue)
	{
		return	GetValue(_T("FileVersion"),strValue);
	}

	bool	GetOriginalFilename(CAtlString& strValue)
	{
		return	GetValue(_T("OriginalFilename"),strValue);
	}

	bool	GetSpecialBuild(CAtlString& strValue)
	{
		return	GetValue(_T("SpecialBuild"),strValue);
	}
};









Copyright (c) 1999-2007 issei. All rights reserved. (運営者情報