bump product version to 6.3.0.0.beta1
[LibreOffice.git] / avmedia / source / vlc / wrapper / SymbolLoader.hxx
bloba4e941f60afe5bc362337d5ae113cbed6fd69a25
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_AVMEDIA_SOURCE_VLC_WRAPPER_SYMBOLLOADER_HXX
11 #define INCLUDED_AVMEDIA_SOURCE_VLC_WRAPPER_SYMBOLLOADER_HXX
12 #if defined(_WIN32)
13 #if !defined WIN32_LEAN_AND_MEAN
14 # define WIN32_LEAN_AND_MEAN
15 #endif
16 # include <windows.h>
17 # include <winreg.h>
18 #endif
19 #include <osl/module.h>
20 #include <rtl/ustring.hxx>
21 #include <sal/log.hxx>
23 #define SYM_MAP(a) { #a, reinterpret_cast<SymbolFunc *>(&a) }
25 namespace avmedia
27 namespace vlc
29 namespace wrapper
31 typedef void (*SymbolFunc) (void);
33 struct ApiMap
35 const char *symName;
36 SymbolFunc *refValue;
39 #if defined( LINUX )
40 const char LibName[] = "libvlc.so.5";
41 #elif defined( MACOSX )
42 const char LibName[] = "/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib";
43 #elif defined( WNT )
44 const char LibName[] = "libvlc.dll";
46 inline OUString GetVLCPath()
48 HKEY hKey;
49 wchar_t arCurrent[MAX_PATH];
50 DWORD dwType, dwCurrentSize = sizeof( arCurrent );
52 //TODO: This one will work only with LibreOffice 32-bit + VLC 32-bit on Win x86_64.
53 const LONG errorCore = ::RegOpenKeyExW( HKEY_LOCAL_MACHINE, L"SOFTWARE\\Wow6432Node\\VideoLAN\\VLC", 0, KEY_READ | KEY_WOW64_64KEY, &hKey );
54 if ( errorCore == ERROR_SUCCESS )
56 if ( ::RegQueryValueExW( hKey, L"InstallDir", NULL, &dwType, (LPBYTE) arCurrent, &dwCurrentSize ) == ERROR_SUCCESS &&
57 dwType == REG_SZ )
59 ::RegCloseKey( hKey );
60 dwCurrentSize -= 2;
61 dwCurrentSize /= 2;
63 return OUString( arCurrent, dwCurrentSize ) + OUString::createFromAscii("\\");
66 ::RegCloseKey( hKey );
69 return OUString();
71 #endif
73 template<size_t N>
74 bool tryLink( oslModule &aModule, const ApiMap ( &pMap )[N] )
76 for (size_t i = 0; i < N; ++i)
78 SymbolFunc aMethod = reinterpret_cast<SymbolFunc>(osl_getFunctionSymbol
79 ( aModule, OUString::createFromAscii( pMap[ i ].symName ).pData ));
80 if ( !aMethod )
82 SAL_WARN("avmedia", "Cannot load method " << pMap[ i ].symName);
83 *pMap[ i ].refValue = nullptr;
84 return false;
86 else
87 *pMap[ i ].refValue = aMethod;
90 return true;
93 template<size_t N>
94 bool InitApiMap( const ApiMap ( &pMap )[N] )
96 #if defined( LINUX ) || defined( MACOSX )
97 OUString const fullPath(LibName);
98 #elif defined( WNT )
99 OUString const fullPath(GetVLCPath() + LibName);
100 #endif
101 SAL_INFO("avmedia", fullPath);
103 oslModule aModule = osl_loadModule( fullPath.pData,
104 SAL_LOADMODULE_DEFAULT );
107 if( aModule == nullptr)
109 SAL_WARN("avmedia", "Cannot load libvlc");
110 return false;
113 if (tryLink( aModule, pMap ))
115 return true;
118 SAL_WARN("avmedia", "Cannot load libvlc");
119 osl_unloadModule( aModule );
121 return false;
127 #endif
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */