USES_CONVERSION; char szFullPath[MAX_PATH];
DWORD dwVerInfoSize = 0;
DWORD dwVerHnd;
VS_FIXEDFILEINFO * pFileInfo; GetModuleFileName(GetDllInstance(), szFullPath, sizeof(szFullPath));
dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
if (dwVerInfoSize)
{
// If we were able to get the information, process it:
HANDLE hMem;
LPVOID lpvMem;
unsigned int uInfoSize = 0; hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
lpvMem = GlobalLock(hMem);
GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
::VerQueryValue(lpvMem, (LPTSTR)_T("\\"), (void**)&pFileInfo, &uInfoSize); int nVer0 = HIWORD(pFileInfo->dwProductVersionMS);
int nVer1 = LOWORD(pFileInfo->dwProductVersionMS);
int nVer2 = HIWORD(pFileInfo->dwProductVersionLS);
int nVer3 = LOWORD(pFileInfo->dwProductVersionLS); char strVersion[50];
memset(strVersion, 0, sizeof(strVersion));
sprintf(strVersion, "%d.%d.%d.%d", nVer0, nVer1, nVer2, nVer3); LOG_DEBUG(("CIGTShow::get_GetVersion : version %s", strVersion)); *pVal = A2BSTR(strVersion); GlobalUnlock(hMem);
GlobalFree(hMem);
}其中GetDllInstance()函数获得模块本身的instance,具体怎么得的,得看模块类型
DWORD dwVerInfoSize = 0;
DWORD dwVerHnd;
VS_FIXEDFILEINFO * pFileInfo; GetModuleFileName(GetDllInstance(), szFullPath, sizeof(szFullPath));
dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
if (dwVerInfoSize)
{
// If we were able to get the information, process it:
HANDLE hMem;
LPVOID lpvMem;
unsigned int uInfoSize = 0; hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
lpvMem = GlobalLock(hMem);
GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
::VerQueryValue(lpvMem, (LPTSTR)_T("\\"), (void**)&pFileInfo, &uInfoSize); int nVer0 = HIWORD(pFileInfo->dwProductVersionMS);
int nVer1 = LOWORD(pFileInfo->dwProductVersionMS);
int nVer2 = HIWORD(pFileInfo->dwProductVersionLS);
int nVer3 = LOWORD(pFileInfo->dwProductVersionLS); char strVersion[50];
memset(strVersion, 0, sizeof(strVersion));
sprintf(strVersion, "%d.%d.%d.%d", nVer0, nVer1, nVer2, nVer3); LOG_DEBUG(("CIGTShow::get_GetVersion : version %s", strVersion)); *pVal = A2BSTR(strVersion); GlobalUnlock(hMem);
GlobalFree(hMem);
}其中GetDllInstance()函数获得模块本身的instance,具体怎么得的,得看模块类型
要是操作系统版本,有api函数可以得到,要是你自己写的软件版本就是你自己顶的;
要是看别的软件的版本,一般都在"帮助/版本信息||关于"中