Platform SDK: Debugging and Error Handling

IMAGE_OPTIONAL_HEADER

The IMAGE_OPTIONAL_HEADER structure represents the optional header format.

typedef struct _IMAGE_OPTIONAL_HEADER {
    WORD    Magic;
    BYTE    MajorLinkerVersion;
    BYTE    MinorLinkerVersion;
    DWORD   SizeOfCode;
    DWORD   SizeOfInitializedData;
    DWORD   SizeOfUninitializedData;
    DWORD   AddressOfEntryPoint;
    DWORD   BaseOfCode;
    DWORD   BaseOfData;
    DWORD   ImageBase;
    DWORD   SectionAlignment;
    DWORD   FileAlignment;
    WORD    MajorOperatingSystemVersion;
    WORD    MinorOperatingSystemVersion;
    WORD    MajorImageVersion;
    WORD    MinorImageVersion;
    WORD    MajorSubsystemVersion;
    WORD    MinorSubsystemVersion;
    DWORD   Win32VersionValue;
    DWORD   SizeOfImage;
    DWORD   SizeOfHeaders;
    DWORD   CheckSum;
    WORD    Subsystem;
    WORD    DllCharacteristics;
    DWORD   SizeOfStackReserve;
    DWORD   SizeOfStackCommit;
    DWORD   SizeOfHeapReserve;
    DWORD   SizeOfHeapCommit;
    DWORD   LoaderFlags;
    DWORD   NumberOfRvaAndSizes;
    IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;

Members

Magic
Specifies the state of the image file. This parameter may be one of the following values.
Value Meaning
IMAGE_NT_OPTIONAL_HDR_MAGIC The file is an executable image.
IMAGE_ROM_OPTIONAL_HDR_MAGIC The file is a ROM image.

MajorLinkerVersion
Major version number of the linker.
MinorLinkerVersion
Minor version number of the linker.
SizeOfCode
The size of the code section, or the sum of all such sections if there are multiple code sections.
SizeOfInitializedData
The size of the initialized data section, or the sum of all such sections if there are multiple initialized data sections.
SizeOfUninitializedData
The size of the uninitialized data section, or the sum of all such sections if there are multiple uninitialized data sections.
AddressOfEntryPoint
Pointer to the entry point function, relative to the image base address. The entry point function is optional for DLLs. When no entry point is present, this member is zero.
BaseOfCode
Pointer to the beginning of the code section, relative to the image base.
BaseOfData
Pointer to the beginning of the data section, relative to the image base.
ImageBase
Preferred address of the first byte of the image when it is loaded in memory. This value is a multiple of 64K bytes. The default value for DLLs is 0x10000000. The default value for Win32-based applications on Windows CE is 0x00010000. The default value for Win32-based applications on Windows NT/Windows 2000 and Windows 95/98 is 0x00400000.
SectionAlignment
The alignment, in bytes, of sections loaded in memory. This value must be greater than or equal to the FileAlignment member. The default value is the page size for the system.
FileAlignment
The alignment, in bytes, of the raw data of sections in the image file. The value should be a power of 2 between 512 and 64K (inclusive). The default is 512. If the SectionAlignment member is less than the system page size, this member must be the same as SectionAlignment.
MajorOperatingSystemVersion
Major version number of the required operating system.
MinorOperatingSystemVersion
Minor version number of the required operating system.
MajorImageVersion
Major version number of the image.
MinorImageVersion
Minor version number of the image.
MajorSubsystemVersion
Major version number of the subsystem.
MinorSubsystemVersion
Minor version number of the subsystem.
Win32VersionValue
This member is reserved.
SizeOfImage
The size of the image, in bytes, including all headers. Must be a multiple of SectionAlignment.
SizeOfHeaders
Combined size of the MS-DOS stub, the PE header, and the section headers, rounded to a multiple of the value specified in the FileAlignment member.
CheckSum
Image file checksum.
Subsystem
Subsystem required to run this image. The following values are defined.
Subsystem Description
IMAGE_SUBSYSTEM_UNKNOWN Unknown subsystem.
IMAGE_SUBSYSTEM_NATIVE No subsystem required.
IMAGE_SUBSYSTEM_WINDOWS_CUI Windows character-mode subsystem.
IMAGE_SUBSYSTEM_POSIX_CUI POSIX character-mode subsystem.
IMAGE_SUBSYSTEM_WINDOWS_CE_GUI Windows CE.

DllCharacteristics
Specifies the DLL characteristics of the image. The following values are defined.
Value Meaning
0x0001 Reserved
0x0002 Reserved
0x0004 Reserved
0x0008 Reserved
0x2000 A WDM driver.

SizeOfStackReserve
The number of bytes to reserve for the stack.
SizeOfStackCommit
The number of bytes to commit for the stack.
SizeOfHeapReserve
The number of bytes to reserve for the local heap.
SizeOfHeapCommit
The number of bytes to commit for the local heap.
LoaderFlags
This member is obsolete.
NumberOfRvaAndSizes
Number of directory entries.
DataDirectory
Pointer to the first IMAGE_DATA_DIRECTORY structure in the data directory.

Remarks

The number of directories is not fixed. Check the NumberOfRvaAndSizes member before looking for a specific directory.

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
  Header: Declared in Winnt.h; include Windows.h.

See Also

Image Help Library Overview, ImageHlp Structures, IMAGE_DATA_DIRECTORY