Mercurial > mplayer.hg
comparison loader/win32.c @ 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 | 3df1e29a3185 |
children | d01c83dcb634 |
comparison
equal
deleted
inserted
replaced
30805:ee9be9626e70 | 30806:5e7d1ade0858 |
---|---|
567 #define MODULE_HANDLE_msvcrt ((HMODULE)0x126) | 567 #define MODULE_HANDLE_msvcrt ((HMODULE)0x126) |
568 #define MODULE_HANDLE_ole32 ((HMODULE)0x127) | 568 #define MODULE_HANDLE_ole32 ((HMODULE)0x127) |
569 #define MODULE_HANDLE_winmm ((HMODULE)0x128) | 569 #define MODULE_HANDLE_winmm ((HMODULE)0x128) |
570 #define MODULE_HANDLE_psapi ((HMODULE)0x129) | 570 #define MODULE_HANDLE_psapi ((HMODULE)0x129) |
571 | 571 |
572 // Fake PE header, since some software (and the Microsoft CRT v8 and newer) | |
573 // assume GetModuleHandle(NULL) returns a pointer to a PE header. | |
574 // We simulate a very simple header with only one section. | |
575 // | |
576 // NOTE: If you have a section called .mixcrt, the Microsoft CRT will assume | |
577 // it's running in a POSIX binary, and stop using EncodePointer/DecodePointer. | |
578 static const struct { | |
579 IMAGE_DOS_HEADER doshdr; | |
580 IMAGE_NT_HEADERS nthdr; | |
581 IMAGE_SECTION_HEADER opthdr; | |
582 } __attribute__((__packed__)) mp_exe = { | |
583 .doshdr.e_lfanew = sizeof(IMAGE_DOS_HEADER), | |
584 .nthdr.FileHeader.NumberOfSections = 1, | |
585 .nthdr.FileHeader.SizeOfOptionalHeader = | |
586 sizeof(IMAGE_NT_HEADERS) - FIELD_OFFSET(IMAGE_NT_HEADERS, OptionalHeader), /* 0xe0 */ | |
587 .opthdr.Name = ".text" | |
588 }; | |
589 | |
572 static HMODULE WINAPI expGetModuleHandleA(const char* name) | 590 static HMODULE WINAPI expGetModuleHandleA(const char* name) |
573 { | 591 { |
574 WINE_MODREF* wm; | 592 WINE_MODREF* wm; |
575 HMODULE result; | 593 HMODULE result; |
576 if(!name) | 594 if(!name) |
577 #ifdef CONFIG_QTX_CODECS | 595 result=(HMODULE)&mp_exe.doshdr; |
578 result=1; | |
579 #else | |
580 result=0; | |
581 #endif | |
582 else | 596 else |
583 { | 597 { |
584 wm=MODULE_FindModule(name); | 598 wm=MODULE_FindModule(name); |
585 if(wm==0)result=0; | 599 if(wm==0)result=0; |
586 else | 600 else |