Page 1 of 1

Finds bitness of .exe

Posted: Fri Mar 18, 2016 11:08 am
by bpd2000
Get-BinaryType function Finds bitness of .exe

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
*/

Re: Finds bitness of .exe

Posted: Fri Mar 18, 2016 12:11 pm
by Rathinagiri
Thank a lot.

Re: Finds bitness of .exe

Posted: Fri Mar 18, 2016 12:13 pm
by serge_girard
Thanks for sharing!

Serge

Re: Finds bitness of .exe

Posted: Fri Mar 18, 2016 12:25 pm
by srvet_claudio
Very nice, I will include in the next release

Re: Finds bitness of .exe

Posted: Fri Mar 18, 2016 12:56 pm
by danielmaximiliano
Gracias por compartir !!!!!!

Re: Finds bitness of .exe

Posted: Fri Mar 18, 2016 1:11 pm
by mustafa
Very useful
Thank you
Mustafa

Re: Finds bitness of .exe

Posted: Sat Mar 19, 2016 3:40 pm
by esgici
Thanks Mr. Dave

Re: Finds bitness of .exe

Posted: Sun Mar 20, 2016 3:57 am
by bpd2000
Thank you to all