GetBinaryType function

Expand
1 out of 3 rated this helpful - Rate this topic

GetBinaryType function

Applies to: desktop apps only

Determines whether a file is an executable (.exe) file, and if so, which subsystem runs the executable file.

Syntax

BOOL WINAPI GetBinaryType(
  __in   LPCTSTR lpApplicationName,
  __out  LPDWORD lpBinaryType
);

Parameters

lpApplicationName [in]

The full path of the file whose executable type is to be determined.

In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

lpBinaryType [out]

A pointer to a variable to receive information about the executable type of the file specified by lpApplicationName. The following constants are defined.

ValueMeaning
SCS_32BIT_BINARY
0

A 32-bit Windows-based application

SCS_64BIT_BINARY
6

A 64-bit Windows-based application.

SCS_DOS_BINARY
1

An MS-DOS – based application

SCS_OS216_BINARY
5

A 16-bit OS/2-based application

SCS_PIF_BINARY
3

A PIF file that executes an MS-DOS – based application

SCS_POSIX_BINARY
4

A POSIX – based application

SCS_WOW_BINARY
2

A 16-bit Windows-based application

 

Return value

If the file is executable, the return value is nonzero. The function sets the variable pointed to by lpBinaryType to indicate the file's executable type.

If the file is not executable, or if the function fails, the return value is zero. To get extended error information, call GetLastError. If the file is a DLL, the last error code is ERROR_BAD_EXE_FORMAT.

Remarks

As an alternative, you can obtain the same information by calling the SHGetFileInfo function, passing the SHGFI_EXETYPE flag in the uFlags parameter.

Symbolic link behavior—If the path points to a symbolic link, the target file is used.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

Unicode and ANSI names

GetBinaryTypeW (Unicode) and GetBinaryTypeA (ANSI)

See also

File Management Functions
SHGetFileInfo
Symbolic Links

 

 

Send comments about this topic to Microsoft

Build date: 5/5/2012

Did you find this helpful?
(1500 characters remaining)
Community Additions ADD
Not always ERROR_BAD_EXE_FORMAT for DLLs
Tested on Windows 2008 and Window7 32-bit and 64-bit machines:

If you run GetBinaryType on a 64-bit machine against 32-bit and 64-bit DLLs, the function returns FALSE
with GetLastError set to ERROR_BAD_EXE_FORMAT, as expected. If you run GetBinaryType on a 32-bit
machine against 32-bit DLLs, the result is the same.

However, if you run GetBinaryType on a 32-bit machine against a 64-bit DLL, the function unexpectedly
returns TRUE with BinaryType set to SCS_64BIT_BINARY. That's quite inconsistent behaviour and not
very helpful.
11/21/2009
Fails for .dll files
This API fails for .dll files. When it says 'If the file is not executable, or if the function fails, the return value is zero' it isn't talking about PE files; it's talking only about files with .exe extensions (applications). 
5/2/2007