Mercurial > mplayer.hg
changeset 30806:5e7d1ade0858
Make GetModuleHandle(NULL) return a valid pointer.
Some codecs, and more recently Microsoft's CRT library, expect GetModuleHandle(NULL)
to return a pointer to the program's PE header mapped in memory. Thus, just returning
0x0 or 0x1 won't do it anymore, so create a minimal PE header and return that.
Patch originally by Gianluigi Tiesi ( mplayer (at) netfarm (dot) it ).
author | sesse |
---|---|
date | Fri, 05 Mar 2010 23:09:36 +0000 |
parents | ee9be9626e70 |
children | 82dd2fbdb772 |
files | loader/win32.c |
diffstat | 1 files changed, 19 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/loader/win32.c Fri Mar 05 21:39:27 2010 +0000 +++ b/loader/win32.c Fri Mar 05 23:09:36 2010 +0000 @@ -569,16 +569,30 @@ #define MODULE_HANDLE_winmm ((HMODULE)0x128) #define MODULE_HANDLE_psapi ((HMODULE)0x129) +// Fake PE header, since some software (and the Microsoft CRT v8 and newer) +// assume GetModuleHandle(NULL) returns a pointer to a PE header. +// We simulate a very simple header with only one section. +// +// NOTE: If you have a section called .mixcrt, the Microsoft CRT will assume +// it's running in a POSIX binary, and stop using EncodePointer/DecodePointer. +static const struct { + IMAGE_DOS_HEADER doshdr; + IMAGE_NT_HEADERS nthdr; + IMAGE_SECTION_HEADER opthdr; +} __attribute__((__packed__)) mp_exe = { + .doshdr.e_lfanew = sizeof(IMAGE_DOS_HEADER), + .nthdr.FileHeader.NumberOfSections = 1, + .nthdr.FileHeader.SizeOfOptionalHeader = + sizeof(IMAGE_NT_HEADERS) - FIELD_OFFSET(IMAGE_NT_HEADERS, OptionalHeader), /* 0xe0 */ + .opthdr.Name = ".text" +}; + static HMODULE WINAPI expGetModuleHandleA(const char* name) { WINE_MODREF* wm; HMODULE result; if(!name) -#ifdef CONFIG_QTX_CODECS - result=1; -#else - result=0; -#endif + result=(HMODULE)&mp_exe.doshdr; else { wm=MODULE_FindModule(name);