Browse Source

win32: fix DllMain definition from header

On the Windows SDK, the definition of DllMain is hardcoded to using
unsigned long as reason parameter.

MinGW has two definitions and the definition of DllMain is different in
MinGW given `_WINDOWS_` is defined or not, leading to a different
prototype between VLC and process.h currently (not taking the `_WINDOWS_`
path):

    ../subprojects/vlc/src/win32/thread.c:688:15: error: conflicting types for 'DllMain'; have 'int(void *, long unsigned int,  void *)'
      688 | int __stdcall DllMain (void *hinstDll, unsigned long fdwReason, void *lpvReserved)
          |               ^~~~~~~
    In file included from ../subprojects/vlc/src/win32/thread.c:33:
    /usr/share/mingw-w64/include/process.h:141:17: note: previous declaration of 'DllMain' with type 'int(void *, unsigned int,  void *)'
      141 |   int __stdcall DllMain(void *_HDllHandle,unsigned _Reason,void *_Reserved);

This was fixed VLC upstream and for newer mingw64 revision with the
[MR !4300] but even though the Windows SDK uses unsigned long, the
documentation[^1] uses DWORD which matches how mingw64 writes the
prototype. By doing the change, we can support older Mingw SDKs (using
the proper definition path) and yet-to-be-released SDKs (where the
definition would use something else than unsigned long).

[MR !4300]: https://code.videolan.org/videolan/vlc/-/merge_requests/4300

[^1]: https://learn.microsoft.com/en-us/windows/win32/dlls/dllmain

So as to use DWORD, we must include <windows.h> first as noted by commit
9ca790a641 that we're essentially
partially reverting here.

After this change, this would work regardless of the SDK vendor or the
SDK version.
pull/201/head
Alexandre Janniaux 5 months ago
committed by Steve Lhomme
parent
commit
5b3b3c6c61
  1. 5
      modules/access/wasapi.c
  2. 3
      src/win32/thread.c

5
modules/access/wasapi.c

@ -24,6 +24,8 @@
# include "config.h"
#endif
#include <windows.h>
#include <initguid.h>
#define COBJMACROS
@ -34,7 +36,6 @@
#define _DECL_DLLMAIN
#include <process.h>
#include <vlc_common.h>
#include <windows.h>
#include <vlc_aout.h>
#include <vlc_demux.h>
#include <vlc_plugin.h>
@ -75,7 +76,7 @@ static msftime_t GetQPC_100ns(void)
static msftime_t (*get_qpc)(void);
int __stdcall DllMain(void *dll, unsigned long reason, void *reserved)
int __stdcall DllMain(void *dll, DWORD reason, void *reserved)
{
(void) dll;
(void) reserved;

3
src/win32/thread.c

@ -30,6 +30,7 @@
#endif
#define _DECL_DLLMAIN
#include <windows.h>
#include <process.h>
#include <vlc_common.h>
#include <vlc_threads.h>
@ -685,7 +686,7 @@ void vlc_threads_setup(libvlc_int_t *vlc)
#define LOOKUP(s) (((s##_) = (s##_ptr)GetProcAddress(h, #s)) != NULL)
int __stdcall DllMain (void *hinstDll, unsigned long fdwReason, void *lpvReserved)
int __stdcall DllMain (void *hinstDll, DWORD fdwReason, void *lpvReserved)
{
(void) hinstDll;
(void) lpvReserved;

Loading…
Cancel
Save