Code: Select all
// bpd2000
//Get-BinaryType function Finds bitness of .exe
/*
The following program is a sample use of GetBinaryType for determining
the type of executable a file is. Evidently GetBinaryType does not
differentiate between console and GUI programs but otherwise it does
provide useful information.
*/
#include "hmg.ch"
Function Main
Local aNewFile := {}, aTypes, cBaseFolder
cBaseFolder := GetStartupFolder()
aTypes := { {'Executable files (*.exe)', '*.exe'} }
aNewFile := GetFile( aTypes, 'Select executable files', cBaseFolder, .T. )
IF !Empty(aNewFile)
Get_Exe_type(aNewFile[1])
Else
Msginfo("No file selected")
Endif
return nil
Function Get_Exe_type(cExe_File)
Local cFileName := cExe_File
Local nExe_Type_Code := 0
nExe_Type_Code := GetBinaryType( cFileName )
If nExe_Type_Code >= 0 .and. nExe_Type_Code <= 6
Do case
Case nExe_Type_Code == 0
MsgInfo( "A 32-bit Windows-based application", "Executable file type" + space(10) )
Case nExe_Type_Code == 1
MsgInfo( "An MS-DOS – based application", "Executable file type" + space(10) )
Case nExe_Type_Code == 2
MsgInfo( "A 16-bit Windows-based application", "Executable file type" + space(10) )
Case nExe_Type_Code == 3
MsgInfo( "A PIF file that executes an MS-DOS – based application", "Executable file type" + space(10) )
Case nExe_Type_Code == 4
MsgInfo( "A POSIX – based application", "Executable file type" + space(10) )
Case nExe_Type_Code == 5
MsgInfo( "A 16-bit OS/2-based application", "Executable file type" + space(10) )
Case nExe_Type_Code == 6
MsgInfo( "A 64-bit Windows-based application.", "Executable file type" + space(10) )
Endcase
ELSE
MsgInfo( "Not executable", "Executable file type" + space(10) )
ENDIF
Return nil
#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"
HB_FUNC( GETBINARYTYPE )
{
DWORD lpBinaryType ;
GetBinaryType(( LPCTSTR ) hb_parc( 1 ),&lpBinaryType) ;
hb_retni(lpBinaryType) ;
}
#pragma ENDDUMP
/*
More info at
https://msdn.microsoft.com/en-us/library/windows/desktop/aa364819%28v=vs.85%29.aspx
https://gist.github.com/MattUebel/2292484
*/