This is the mail archive of the
mailing list for the binutils project.
RE: [patch]: Add MS __ImageBase symbol to 32-bit pe.em
The usual expression is:
#pragma section(".base", long, read)
extern "C" __declspec(allocate(".base"))
const IMAGE_DOS_HEADER __ImageBase;
extern "C" const IMAGE_DOS_HEADER __ImageBase;
and used like:
PIMAGE_DOS_HEADER dhd = &__ImageBase;
HINSTANCE hModulehandle = (HINSTANCE)&__ImageBase; // e.g. ATL
Where __ImageBase represents the PE DOS header of a binary. This variable is not defined anywhere, nor is it documented. ATL uses this method to get the module handle (HINSTANCE) of the current process, thus it must always point to the current executable image, right? As I understand, using __ImageBase in a DLL, you will get the PE header of the executable.
I always thought it was defined by the MS compiler. So this variable is valid for mingw also?