PB read version number from exe

This is for pB10.5 or later, Unicode style.

FUNCTION ulong GetFileVersionInfoSizeW  &
( REF string lpFilename, REF ulong lpdwHandle ) &
LIBRARY “version.dll”

FUNCTION integer GetFileVersionInfoW &
( REF string lpFilename, REF ulong lpdwHandle, ulong dwLen, &
REF string lpData )  &
LIBRARY “version.dll”

FUNCTION boolean VerQueryValueW &
( REF string lpBlock, string lpSubBlock, REF long lpBuffer, &
REF uint puLen )  &
LIBRARY “version.dll”

( REF string d, long s, long l )  &
LIBRARY “kernel32.dll”  &
ALIAS FOR RtlMoveMemory

FUNCTION ulong GetModuleFileName (ulong hinstModule, ref string lpszPath, ulong cchPath )  &
ALIAS FOR “GetModuleFileNameA;ansi”  // ;ansi  required for PB10 or later

// function of_get_version()
ulong  dwHandle, dwLength
string ls_Buff, ls_key
uint   lui_length
long   ll_pointer
string ls_filename  
integer li_rc
string  ls_result = ‘?’
string ls_EXE_FILE_NAME
String ls_fullpath
ulong lul_handle, lul_length = 512

lul_handle = handle( getapplication() )

If lul_handle = 0 Then //IDE MODE
RETURN ‘[IDE mode]’
End if

// running from EXE
GetModuleFilename( lul_handle, ls_fullpath, lul_length )

//ls_filename = GetCurrentDirectory ( ) + “\” + ls_EXE_FILE_NAME
ls_filename = ls_fullpath

dwLength = GetFileVersionInfoSizeW( ls_filename, dwHandle )
IF dwLength <= 0 THEN RETURN ls_result END IF ls_Buff = Space( dwLength ) li_rc = GetFileVersionInfoW( ls_filename, dwHandle, dwLength, ls_Buff ) IF li_rc = 0 THEN RETURN ls_result END IF // the strange numbers below represents the country and language // of the version resource. ls_key = "\StringFileInfo40904e4\FileVersion" IF NOT VerQueryValueW( ls_buff, ls_key, ll_pointer, lui_length ) OR & lui_length <= 0 THEN ls_result = "?" ELSE ls_result = Space( lui_length ) CopyMemoryA( ls_result, ll_pointer, lui_length*2 ) // unicode END IF return ls_result [/sourcecode] More to investigate: 1. How to deal with component on EAServer? Couldn't find solution from WCF architecture. Don't we care the version number of a remote service?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s