HiWord/LoWord

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by sk.

Trying to read the version number of an EXE-file I used following code:

Code: Select all

Procedure.l HiWord(dw)         If dw And $80000000 
            ProcedureReturn (dw/65535) - 1 
        Else 
            ProcedureReturn  dw/65535 
        EndIf 
    EndProcedure 

    Procedure.l LoWord(dw) 
        If dw And $8000 
            ProcedureReturn $8000 Or (dw And $7FFF) 
        Else 
            ProcedureReturn dw And $FFFF 
        EndIf 
    EndProcedure 

    Procedure.s GetFileVersion(Filepath$) 
        Version$ = "" 
        If OpenLibrary(1,"Version.dll") 
            Length = CallFunction(1, "GetFileVersionInfoSizeA",Filepath$, @Zero) 
            If Length > 0 
                Dim btBuffer.b(Length) 
                Item$ = "\" 
                If CallFunction(1, "GetFileVersionInfoA", Filepath$, 0, @Length, @btBuffer(0)) 
                    If CallFunction(1, "VerQueryValueA",@btBuffer(0), Item$, @lplpBuffer, @puLen) 
                        CopyMemory(lplpBuffer, uFI.VS_FIXEDFILEINFO, SizeOf(VS_FIXEDFILEINFO)) 
                    ;// ------------------------------------------------------------------------ 
                        Debug HiWord(PeekL(@uFI\dwFileVersionMS))    ; =    9 should be   10 ??? 
                        Debug LoWord(PeekL(@uFI\dwFileVersionMS))    ; =    1 should be    0 ??? 
                        If PeekL(@uFI\dwFileVersionLS) 
                            Debug HiWord(PeekL(@uFI\dwFileVersionLS)); = 4218 should be 4219 ??? 
                            Debug LoWord(PeekL(@uFI\dwFileVersionLS)); =    1 should be    0 ??? 
                        EndIf 
                    ;// ------------------------------------------------------------------------ 
                    EndIf 
                EndIf 
            EndIf 
            CloseLibrary(1) 
        EndIf 
        ProcedureReturn Version$ 
        
    EndProcedure 

    Debug GetFileVersion("C:\Programme\Microsoft Office\Office10\WINWORD.EXE")
The return values of the HiWord-/LoWord-Routines are exactly -1 of the expected values - any hints?
Do anyone knows an easier way to read this version data from EXE-Files?

Thanks!

sk
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

I see that you use 'And', 'Or' in your loword procedure, this is wrong cause these aren't binary operators but logical ones i.e. they retrun '1' or '0'. The binary And operator is '&' and the binary Or operator is '|'.

If you want the Hi-word and Low-word out of a long word do it like this:

Code: Select all

Procedure GetHiword(a.l)
  ProcedureReturn (a>>16 & $ffff)
EndProcedure

Procedure GetLowword(a.l)
  ProcedureReturn (a & $ffff)
EndProcedure
I also saw that you've made a sleigt error in you Hiword procedure, you should have divided with 65536 instead of 65535.. These procedures i've provided should produce the right result, i haven't tested but they should :wink:
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by sk.

Thanks!
That's because I'm working with VB for quite a long time (too long?) - but the time will come I see the differences :wink:
Post Reply