diff mbox

[FFmpeg-devel] compat: LoadLibrary isn't available on UWP/WinRT

Message ID 20170602132907.32176-1-hugo@beauzee.fr
State New
Headers show

Commit Message

Hugo Beauzée-Luyssen June 2, 2017, 1:29 p.m. UTC
---
 compat/w32dlfcn.h | 4 ++++
 1 file changed, 4 insertions(+)

Comments

wm4 June 2, 2017, 2:11 p.m. UTC | #1
On Fri,  2 Jun 2017 15:29:07 +0200
Hugo Beauzée-Luyssen <hugo@beauzee.fr> wrote:

> ---
>  compat/w32dlfcn.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/compat/w32dlfcn.h b/compat/w32dlfcn.h
> index bc9bb8c9f5..308763be53 100644
> --- a/compat/w32dlfcn.h
> +++ b/compat/w32dlfcn.h
> @@ -71,7 +71,11 @@ exit:
>  #ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
>  #   define LOAD_LIBRARY_SEARCH_SYSTEM32        0x00000800
>  #endif
> +#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
>      return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32);
> +#else
> +    return NULL;
> +#endif
>  }
>  #define dlopen(name, flags) win32_dlopen(name)
>  #define dlclose FreeLibrary

Isn't it that LoadLibraryW is available, just not the A version?
Aaron Levinson June 3, 2017, 5:54 p.m. UTC | #2
On 6/2/2017 7:11 AM, wm4 wrote:
> On Fri,  2 Jun 2017 15:29:07 +0200
> Hugo Beauzée-Luyssen <hugo@beauzee.fr> wrote:
> 
>> ---
>>   compat/w32dlfcn.h | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/compat/w32dlfcn.h b/compat/w32dlfcn.h
>> index bc9bb8c9f5..308763be53 100644
>> --- a/compat/w32dlfcn.h
>> +++ b/compat/w32dlfcn.h
>> @@ -71,7 +71,11 @@ exit:
>>   #ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
>>   #   define LOAD_LIBRARY_SEARCH_SYSTEM32        0x00000800
>>   #endif
>> +#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
>>       return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32);
>> +#else
>> +    return NULL;
>> +#endif
>>   }
>>   #define dlopen(name, flags) win32_dlopen(name)
>>   #define dlclose FreeLibrary
> 
> Isn't it that LoadLibraryW is available, just not the A version?

According to 
https://msdn.microsoft.com/en-us/library/windows/apps/mt654039.aspx#_api-ms-win-core-libraryloader-l1-2-0.dll 
, both the A and W versions of LoadLibrary and LoadLibraryEx would seem 
to be available on UWP.  However, at the same time, I don't see any of 
the LoadLibrary APIs listed at either 
https://msdn.microsoft.com/en-us/library/windows/apps/dn424765.aspx , 
https://docs.microsoft.com/en-us/uwp/win32-and-com/win32-apis , or 
https://docs.microsoft.com/en-us/uwp/win32-and-com/win32-extension-apis 
, so perhaps LoadLibrary and LoadLibraryEx aren't supported.  So, there 
appears to be some conflicting information on MSDN.  According to 
https://msdn.microsoft.com/en-us/library/mt186162.aspx , it is necessary 
to use LoadPackagedLibrary in UWP apps instead of LoadLibrary or 
LoadLibraryEx.

According to the article, "These macros are only available in Windows 
SDK 8.1 and later, so if your code needs to compile with earlier 
versions of the Windows SDK or for other platforms besides Windows, then 
you should also consider the case that none of them are defined."  I'm 
not aware of ffmpeg necessarily having a requirement that it be built 
with the Windows 8.1 SDK or later, and this lack of requirement would 
tend to indicate that the proposed patch isn't sufficient.  Plus, there 
is no reason to #define LOAD_LIBRARY_SEARCH_SYSTEM32 if the code won't 
be built anyway.

Aaron Levinson
wm4 June 6, 2017, 2:13 p.m. UTC | #3
On Sat, 3 Jun 2017 10:54:08 -0700
Aaron Levinson <alevinsn@aracnet.com> wrote:

> On 6/2/2017 7:11 AM, wm4 wrote:
> > On Fri,  2 Jun 2017 15:29:07 +0200
> > Hugo Beauzée-Luyssen <hugo@beauzee.fr> wrote:
> >   
> >> ---
> >>   compat/w32dlfcn.h | 4 ++++
> >>   1 file changed, 4 insertions(+)
> >>
> >> diff --git a/compat/w32dlfcn.h b/compat/w32dlfcn.h
> >> index bc9bb8c9f5..308763be53 100644
> >> --- a/compat/w32dlfcn.h
> >> +++ b/compat/w32dlfcn.h
> >> @@ -71,7 +71,11 @@ exit:
> >>   #ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
> >>   #   define LOAD_LIBRARY_SEARCH_SYSTEM32        0x00000800
> >>   #endif
> >> +#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
> >>       return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32);
> >> +#else
> >> +    return NULL;
> >> +#endif
> >>   }
> >>   #define dlopen(name, flags) win32_dlopen(name)
> >>   #define dlclose FreeLibrary  
> > 
> > Isn't it that LoadLibraryW is available, just not the A version?  
> 
> According to 
> https://msdn.microsoft.com/en-us/library/windows/apps/mt654039.aspx#_api-ms-win-core-libraryloader-l1-2-0.dll 
> , both the A and W versions of LoadLibrary and LoadLibraryEx would seem 
> to be available on UWP.  However, at the same time, I don't see any of 
> the LoadLibrary APIs listed at either 
> https://msdn.microsoft.com/en-us/library/windows/apps/dn424765.aspx , 
> https://docs.microsoft.com/en-us/uwp/win32-and-com/win32-apis , or 
> https://docs.microsoft.com/en-us/uwp/win32-and-com/win32-extension-apis 
> , so perhaps LoadLibrary and LoadLibraryEx aren't supported.  So, there 
> appears to be some conflicting information on MSDN.  According to 
> https://msdn.microsoft.com/en-us/library/mt186162.aspx , it is necessary 
> to use LoadPackagedLibrary in UWP apps instead of LoadLibrary or 
> LoadLibraryEx.
> 
> According to the article, "These macros are only available in Windows 
> SDK 8.1 and later, so if your code needs to compile with earlier 
> versions of the Windows SDK or for other platforms besides Windows, then 
> you should also consider the case that none of them are defined."  I'm 
> not aware of ffmpeg necessarily having a requirement that it be built 
> with the Windows 8.1 SDK or later, and this lack of requirement would 
> tend to indicate that the proposed patch isn't sufficient.  Plus, there 
> is no reason to #define LOAD_LIBRARY_SEARCH_SYSTEM32 if the code won't 
> be built anyway.

Actually libwinstorecompat seems to have a wrapper:

HMODULE WINAPI LoadLibraryW(LPCWSTR lpFileName)
{
    return LoadPackagedLibrary(lpFileName, 0);
}

(Good one, Microsoft...)
diff mbox

Patch

diff --git a/compat/w32dlfcn.h b/compat/w32dlfcn.h
index bc9bb8c9f5..308763be53 100644
--- a/compat/w32dlfcn.h
+++ b/compat/w32dlfcn.h
@@ -71,7 +71,11 @@  exit:
 #ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
 #   define LOAD_LIBRARY_SEARCH_SYSTEM32        0x00000800
 #endif
+#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
     return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32);
+#else
+    return NULL;
+#endif
 }
 #define dlopen(name, flags) win32_dlopen(name)
 #define dlclose FreeLibrary