[vlc-devel] [PATCH 2/3] win32: use vlc_load_syslib() instead of LoadLibrary for system DLLs

Steve Lhomme robux4 at videolabs.io
Thu Mar 9 16:02:36 CET 2017


---
 modules/audio_output/directsound.c               |  5 ++-
 modules/codec/avcodec/d3d11va.c                  |  4 +-
 modules/codec/avcodec/directx_va.c               |  3 +-
 modules/codec/avcodec/directx_va.h               |  2 +-
 modules/codec/avcodec/dxva2.c                    |  2 +-
 modules/codec/dmo/dmo.c                          | 49 ++++++++++++------------
 modules/codec/mft.c                              |  3 +-
 modules/gui/qt/components/simple_preferences.cpp |  2 +-
 modules/text_renderer/freetype/fonts/dwrite.cpp  |  3 +-
 modules/video_output/win32/common.c              |  3 +-
 modules/video_output/win32/direct3d11.c          | 11 +++---
 modules/video_output/win32/direct3d9.c           | 10 ++---
 modules/video_output/win32/directdraw.c          |  6 +--
 13 files changed, 55 insertions(+), 48 deletions(-)

diff --git a/modules/audio_output/directsound.c b/modules/audio_output/directsound.c
index 967971a353..9188ff03d0 100644
--- a/modules/audio_output/directsound.c
+++ b/modules/audio_output/directsound.c
@@ -34,6 +34,7 @@
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
+#include <vlc_modules.h>
 #include <vlc_aout.h>
 #include <vlc_charset.h>
 #include <vlc_memory.h>
@@ -1043,7 +1044,7 @@ static int ReloadDirectXDevices( vlc_object_t *p_this, char const *psz_name,
 
     (void) psz_name;
 
-    HANDLE hdsound_dll = LoadLibrary(_T("DSOUND.DLL"));
+    HMODULE hdsound_dll = vlc_load_syslib("DSOUND.DLL");
     if( hdsound_dll == NULL )
     {
         msg_Warn( p_this, "cannot open DSOUND.DLL" );
@@ -1078,7 +1079,7 @@ static int Open(vlc_object_t *obj)
 {
     audio_output_t *aout = (audio_output_t *)obj;
 
-    HINSTANCE hdsound_dll = LoadLibrary(_T("DSOUND.DLL"));
+    HMODULE hdsound_dll = vlc_load_syslib("DSOUND.DLL");
     if (hdsound_dll == NULL)
     {
         msg_Warn(aout, "cannot open DSOUND.DLL");
diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 4ef9ac80ea..a6795cd3db 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -452,7 +452,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
         return VLC_ENOMEM;
 
 #if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
-    sys->dxgidebug_dll = LoadLibrary(TEXT("DXGIDEBUG.DLL"));
+    sys->dxgidebug_dll = vlc_load_syslib("DXGIDEBUG.DLL");
 #endif
 
     dx_sys = &sys->dx_sys;
@@ -470,7 +470,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     dx_sys->pf_get_input_list          = DxGetInputList;
     dx_sys->pf_setup_output            = DxSetupOutput;
     dx_sys->pf_alloc_surface_pic       = DxAllocPicture;
-    dx_sys->psz_decoder_dll            = TEXT("D3D11.DLL");
+    dx_sys->psz_decoder_dll            = "D3D11.DLL";
 
     va->sys = sys;
 
diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index 1c26edcd6e..ef35213a89 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -33,6 +33,7 @@
 #include <vlc_common.h>
 #include <vlc_codecs.h>
 #include <vlc_codec.h>
+#include <vlc_modules.h>
 
 #define COBJMACROS
 
@@ -451,7 +452,7 @@ int directx_va_Open(vlc_va_t *va, directx_sys_t *dx_sys,
 
     if (b_dll) {
         /* Load dll*/
-        dx_sys->hdecoder_dll = LoadLibrary(dx_sys->psz_decoder_dll);
+        dx_sys->hdecoder_dll = vlc_load_syslib(dx_sys->psz_decoder_dll);
         if (!dx_sys->hdecoder_dll) {
             msg_Warn(va, "cannot load DirectX decoder DLL");
             goto error;
diff --git a/modules/codec/avcodec/directx_va.h b/modules/codec/avcodec/directx_va.h
index 0561dcdae1..88ceda8b52 100644
--- a/modules/codec/avcodec/directx_va.h
+++ b/modules/codec/avcodec/directx_va.h
@@ -64,7 +64,7 @@ typedef struct
 
     /* DLL */
     HINSTANCE             hdecoder_dll;
-    const TCHAR           *psz_decoder_dll;
+    const char            *psz_decoder_dll;
 
     /* Direct3D */
     IUnknown              *d3ddev;
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index d609ce07ae..eea7f45f94 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -350,7 +350,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
         return VLC_ENOMEM;
 
     /* Load dll*/
-    sys->hd3d9_dll = LoadLibrary(TEXT("D3D9.DLL"));
+    sys->hd3d9_dll = vlc_load_syslib("D3D9.DLL");
     if (!sys->hd3d9_dll) {
         msg_Warn(va, "cannot load d3d9.dll");
         goto error;
diff --git a/modules/codec/dmo/dmo.c b/modules/codec/dmo/dmo.c
index ef40f3859f..5f8ed5af4c 100644
--- a/modules/codec/dmo/dmo.c
+++ b/modules/codec/dmo/dmo.c
@@ -35,6 +35,7 @@
 #include <vlc_plugin.h>
 #include <vlc_codec.h>
 #include <vlc_codecs.h>
+#include <vlc_modules.h>
 
 #ifdef _WIN32
 #   include <objbase.h>
@@ -167,7 +168,7 @@ static const GUID guid_wmv9_enc = { 0xd23b90d0, 0x144f, 0x46bd,{ 0x84, 0x1d, 0x5
 typedef struct
 {
     vlc_fourcc_t i_fourcc;
-    const TCHAR  *psz_dll;
+    const char   *psz_dll;
     const GUID   *p_guid;
 
 } codec_dll;
@@ -175,30 +176,30 @@ typedef struct
 static const codec_dll decoders_table[] =
 {
     /* WVC1 */
-    { VLC_CODEC_VC1,    TEXT("wvc1dmod.dll"), &guid_wvc1 },
+    { VLC_CODEC_VC1,    "wvc1dmod.dll", &guid_wvc1 },
     /* WMV3 */
-    { VLC_CODEC_WMV3,   TEXT("wmv9dmod.dll"), &guid_wmv9 },
+    { VLC_CODEC_WMV3,   "wmv9dmod.dll", &guid_wmv9 },
     /* WMV2 */
-    { VLC_CODEC_WMV2,   TEXT("wmvdmod.dll"), &guid_wmv },
+    { VLC_CODEC_WMV2,   "wmvdmod.dll", &guid_wmv },
     /* WMV1 */
-    { VLC_CODEC_WMV1,   TEXT("wmvdmod.dll"), &guid_wmv },
+    { VLC_CODEC_WMV1,   "wmvdmod.dll", &guid_wmv },
     /* Screen codecs */
-    { VLC_CODEC_MSS2,   TEXT("WMVSDECD.DLL"), &guid_wms },
-    { VLC_CODEC_MSS2,   TEXT("wmsdmod.dll"),  &guid_wms },
-    { VLC_CODEC_MSS1,   TEXT("WMVSDECD.DLL"), &guid_wms },
-    { VLC_CODEC_MSS1,   TEXT("wmsdmod.dll"),  &guid_wms },
+    { VLC_CODEC_MSS2,   "WMVSDECD.DLL", &guid_wms },
+    { VLC_CODEC_MSS2,   "wmsdmod.dll",  &guid_wms },
+    { VLC_CODEC_MSS1,   "WMVSDECD.DLL", &guid_wms },
+    { VLC_CODEC_MSS1,   "wmsdmod.dll",  &guid_wms },
     /* Windows Media Video Adv */
-    { VLC_CODEC_WMVA,   TEXT("wmvadvd.dll"), &guid_wmva },
+    { VLC_CODEC_WMVA,   "wmvadvd.dll", &guid_wmva },
 
     /* WMA 3 */
-    { VLC_CODEC_WMAP,   TEXT("wma9dmod.dll"), &guid_wma9 },
-    { VLC_CODEC_WMAL,   TEXT("wma9dmod.dll"), &guid_wma9 },
+    { VLC_CODEC_WMAP,   "wma9dmod.dll", &guid_wma9 },
+    { VLC_CODEC_WMAL,   "wma9dmod.dll", &guid_wma9 },
 
     /* WMA 2 */
-    { VLC_CODEC_WMA2,   TEXT("wma9dmod.dll"), &guid_wma9 },
+    { VLC_CODEC_WMA2,   "wma9dmod.dll", &guid_wma9 },
 
     /* WMA Speech */
-    { VLC_CODEC_WMAS,   TEXT("wmspdmod.dll"), &guid_wma },
+    { VLC_CODEC_WMAS,   "wmspdmod.dll", &guid_wma },
 
     /* */
     { 0, NULL, NULL }
@@ -207,23 +208,23 @@ static const codec_dll decoders_table[] =
 static const codec_dll encoders_table[] =
 {
     /* WMV3 */
-    { VLC_CODEC_WMV3, TEXT("wmvdmoe2.dll"), &guid_wmv_enc2 },
+    { VLC_CODEC_WMV3, "wmvdmoe2.dll", &guid_wmv_enc2 },
     /* WMV2 */
-    { VLC_CODEC_WMV2, TEXT("wmvdmoe2.dll"), &guid_wmv_enc2 },
+    { VLC_CODEC_WMV2, "wmvdmoe2.dll", &guid_wmv_enc2 },
     /* WMV1 */
-    { VLC_CODEC_WMV1, TEXT("wmvdmoe2.dll"), &guid_wmv_enc2 },
+    { VLC_CODEC_WMV1, "wmvdmoe2.dll", &guid_wmv_enc2 },
 
     /* WMA 3 */
-    { VLC_CODEC_WMAP, TEXT("wmadmoe.dll"), &guid_wma_enc },
+    { VLC_CODEC_WMAP, "wmadmoe.dll", &guid_wma_enc },
     /* WMA 2 */
-    { VLC_CODEC_WMA2, TEXT("wmadmoe.dll"), &guid_wma_enc },
+    { VLC_CODEC_WMA2, "wmadmoe.dll", &guid_wma_enc },
 
     /* WMV3 v11 */
-    { VLC_CODEC_WMV3, TEXT("wmvencod.dll"), &guid_wmv9_enc },
+    { VLC_CODEC_WMV3, "wmvencod.dll", &guid_wmv9_enc },
     /* WMV2 v11 */
-    { VLC_CODEC_WMV2, TEXT("wmvxencd.dll"), &guid_wmv8_enc },
+    { VLC_CODEC_WMV2, "wmvxencd.dll", &guid_wmv8_enc },
     /* WMV1 v11 */
-    { VLC_CODEC_WMV1, TEXT("wmvxencd.dll"), &guid_wmv8_enc },
+    { VLC_CODEC_WMV1, "wmvxencd.dll", &guid_wmv8_enc },
 
     /* */
     { 0, NULL, NULL }
@@ -680,7 +681,7 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
     }
 
     /* Load msdmo DLL */
-    *p_hmsdmo_dll = LoadLibrary( TEXT( "msdmo.dll" ) );
+    *p_hmsdmo_dll = vlc_load_syslib("msdmo.dll");
     if( *p_hmsdmo_dll == NULL )
     {
         msg_Dbg( p_this, "failed loading msdmo.dll" );
@@ -753,7 +754,7 @@ loader:
     if( codecs_table[i_codec].i_fourcc == 0 )
         return VLC_EGENERIC;    /* Can't happen */
 
-    *p_hmsdmo_dll = LoadLibrary( codecs_table[i_codec].psz_dll );
+    *p_hmsdmo_dll = vlc_load_syslib( codecs_table[i_codec].psz_dll );
     if( *p_hmsdmo_dll == NULL )
     {
         msg_Dbg( p_this, "failed loading '"PRIs"'",
diff --git a/modules/codec/mft.c b/modules/codec/mft.c
index fbd85d4bdc..30d23c2253 100644
--- a/modules/codec/mft.c
+++ b/modules/codec/mft.c
@@ -46,6 +46,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_codec.h>
+#include <vlc_modules.h>
 #include "../packetizer/h264_nal.h"
 #define _VIDEOINFOHEADER_
 #include <vlc_codecs.h>
@@ -1087,7 +1088,7 @@ static int FindMFT(decoder_t *p_dec)
 static int LoadMFTLibrary(MFHandle *mf)
 {
 #if _WIN32_WINNT < _WIN32_WINNT_WIN7 || VLC_WINSTORE_APP
-    mf->mfplat_dll = LoadLibrary(TEXT("mfplat.dll"));
+    mf->mfplat_dll = vlc_load_syslib("mfplat.dll");
     if (!mf->mfplat_dll)
         return VLC_EGENERIC;
 
diff --git a/modules/gui/qt/components/simple_preferences.cpp b/modules/gui/qt/components/simple_preferences.cpp
index b9e1d01a41..9949e8d031 100644
--- a/modules/gui/qt/components/simple_preferences.cpp
+++ b/modules/gui/qt/components/simple_preferences.cpp
@@ -609,7 +609,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
             }
             CONFIG_GENERIC( "avcodec-hw", StringList, ui.hwAccelLabel, hwAccelModule );
 #ifdef _WIN32
-            HINSTANCE hdxva2_dll = LoadLibrary(TEXT("DXVA2.DLL") );
+            HMODULE hdxva2_dll = vlc_load_syslib("DXVA2.DLL");
             if( !hdxva2_dll )
                 ui.hwAccelModule->setEnabled( false );
             else
diff --git a/modules/text_renderer/freetype/fonts/dwrite.cpp b/modules/text_renderer/freetype/fonts/dwrite.cpp
index addc91a326..405d377386 100644
--- a/modules/text_renderer/freetype/fonts/dwrite.cpp
+++ b/modules/text_renderer/freetype/fonts/dwrite.cpp
@@ -28,6 +28,7 @@
 #include <vlc_common.h>
 #include <vlc_filter.h>
 #include <vlc_charset.h>
+#include <vlc_modules.h>
 
 #include <dwrite_2.h>
 #include <wrl/client.h>
@@ -113,7 +114,7 @@ extern "C" int InitDWrite( filter_t *p_filter )
 #if VLC_WINSTORE_APP
         p_dw_sys = new dw_sys_t( p_dw_dll );
 #else
-        p_dw_dll = LoadLibrary( TEXT( "Dwrite.dll" ) );
+        p_dw_dll = vlc_load_syslib( "Dwrite.dll" );
         if( p_dw_dll == NULL )
             return VLC_EGENERIC;
 
diff --git a/modules/video_output/win32/common.c b/modules/video_output/win32/common.c
index f2b97b88e3..68dc208f04 100644
--- a/modules/video_output/win32/common.c
+++ b/modules/video_output/win32/common.c
@@ -33,6 +33,7 @@
 #endif
 
 #include <vlc_common.h>
+#include <vlc_modules.h>
 #include <vlc_vout_display.h>
 
 #include <windows.h>
@@ -122,7 +123,7 @@ int CommonInit(vout_display_t *vd)
     DisableScreensaver (vd);
 #endif
 #if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
-    sys->dxgidebug_dll = LoadLibrary(TEXT("DXGIDEBUG.DLL"));
+    sys->dxgidebug_dll = vlc_load_syslib("DXGIDEBUG.DLL");
 #endif
 
     return VLC_SUCCESS;
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index e7c9185609..bc22203687 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -33,6 +33,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_vout_display.h>
+#include <vlc_modules.h>
 
 #include <assert.h>
 #include <math.h>
@@ -371,7 +372,7 @@ static int OpenHwnd(vout_display_t *vd)
     if (!sys)
         return VLC_ENOMEM;
 
-    sys->hd3d11_dll = LoadLibrary(TEXT("D3D11.DLL"));
+    sys->hd3d11_dll = vlc_load_syslib("D3D11.DLL");
     if (!sys->hd3d11_dll) {
         msg_Warn(vd, "cannot load d3d11.dll, aborting");
         return VLC_EGENERIC;
@@ -1303,11 +1304,11 @@ static void Direct3D11Destroy(vout_display_t *vd)
 static HINSTANCE Direct3D11LoadShaderLibrary(void)
 {
     HINSTANCE instance = NULL;
+    char filename[19];
     /* d3dcompiler_47 is the latest on windows 8.1 */
     for (int i = 47; i > 41; --i) {
-        TCHAR filename[19];
-        _sntprintf(filename, 19, TEXT("D3DCOMPILER_%d.dll"), i);
-        instance = LoadLibrary(filename);
+        snprintf(filename, 19, "D3DCOMPILER_%d.dll", i);
+        instance = vlc_load_syslib(filename);
         if (instance) break;
     }
     return instance;
@@ -1328,7 +1329,7 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
     HRESULT hr = S_OK;
 
 # if !defined(NDEBUG)
-    HINSTANCE sdklayer_dll = LoadLibrary(TEXT("d3d11_1sdklayers.dll"));
+    HMODULE sdklayer_dll = vlc_load_syslib("d3d11_1sdklayers.dll");
     if (sdklayer_dll) {
         creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
         FreeLibrary(sdklayer_dll);
diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index f190e65147..4a7da12986 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -43,7 +43,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_vout_display.h>
-#include <vlc_charset.h> /* ToT function */
+#include <vlc_modules.h>
 
 #include <windows.h>
 #include <d3d9.h>
@@ -628,10 +628,10 @@ static void Manage (vout_display_t *vd)
 static HINSTANCE Direct3D9LoadShaderLibrary(void)
 {
     HINSTANCE instance = NULL;
+    char filename[16];
     for (int i = 43; i > 23; --i) {
-        TCHAR filename[16];
-        _sntprintf(filename, 16, TEXT("D3dx9_%d.dll"), i);
-        instance = LoadLibrary(filename);
+        snprintf(filename, 16, "D3dx9_%d.dll", i);
+        instance = vlc_load_syslib(filename);
         if (instance)
             break;
     }
@@ -645,7 +645,7 @@ static int Direct3D9Create(vout_display_t *vd)
 {
     vout_display_sys_t *sys = vd->sys;
 
-    sys->hd3d9_dll = LoadLibrary(TEXT("D3D9.DLL"));
+    sys->hd3d9_dll = vlc_load_syslib("D3D9.DLL");
     if (!sys->hd3d9_dll) {
         msg_Warn(vd, "cannot load d3d9.dll, aborting");
         return VLC_EGENERIC;
diff --git a/modules/video_output/win32/directdraw.c b/modules/video_output/win32/directdraw.c
index d3c59310e3..f83bfe99a9 100644
--- a/modules/video_output/win32/directdraw.c
+++ b/modules/video_output/win32/directdraw.c
@@ -44,7 +44,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_vout_display.h>
-#include <vlc_charset.h>    /* FromT */
+#include <vlc_modules.h>
 
 #include <windows.h>
 #include <ddraw.h>
@@ -205,7 +205,7 @@ static int Open(vlc_object_t *object)
         return VLC_ENOMEM;
 
     /* Load direct draw DLL */
-    sys->hddraw_dll = LoadLibrary(_T("DDRAW.DLL"));
+    sys->hddraw_dll = vlc_load_syslib("DDRAW.DLL");
     if (!sys->hddraw_dll) {
         msg_Warn(vd, "DirectXInitDDraw failed loading ddraw.dll");
         free(sys);
@@ -1494,7 +1494,7 @@ static int FindDevicesCallback(vlc_object_t *object, const char *name,
     ctx.count = 1;
 
     /* Load direct draw DLL */
-    HINSTANCE hddraw_dll = LoadLibrary(_T("DDRAW.DLL"));
+    HMODULE hddraw_dll = vlc_load_syslib("DDRAW.DLL");
     if (hddraw_dll != NULL)
     {
         /* Enumerate displays */
-- 
2.11.1



More information about the vlc-devel mailing list