File tree 5 files changed +110
-1
lines changed
5 files changed +110
-1
lines changed Original file line number Diff line number Diff line change
1
+ #include " stdafx.h"
2
+ #include " dynamic_library.h"
3
+
4
+ #ifdef _WIN32
5
+ #include < Windows.h>
6
+ #else
7
+ #include < dlfcn.h>
8
+ #endif
9
+
10
+ namespace utils
11
+ {
12
+ dynamic_library::dynamic_library (const std::string &path)
13
+ {
14
+ load (path);
15
+ }
16
+
17
+ dynamic_library::~dynamic_library ()
18
+ {
19
+ close ();
20
+ }
21
+
22
+ bool dynamic_library::load (const std::string &path)
23
+ {
24
+ #ifdef _WIN32
25
+ m_handle = LoadLibraryA (path.c_str ());
26
+ #else
27
+ m_handle = dlopen (path.c_str (), RTLD_LAZY);
28
+ #endif
29
+ return loaded ();
30
+ }
31
+
32
+ void dynamic_library::close ()
33
+ {
34
+ #ifdef _WIN32
35
+ FreeLibrary ((HMODULE)m_handle);
36
+ #else
37
+ dlclose (m_handle);
38
+ #endif
39
+ m_handle = nullptr ;
40
+ }
41
+
42
+ void *dynamic_library::get_impl (const std::string &name) const
43
+ {
44
+ #ifdef _WIN32
45
+ return GetProcAddress ((HMODULE)m_handle, name.c_str ());
46
+ #else
47
+ return dlsym (m_handle, (char *)name.c_str ());
48
+ #endif
49
+ }
50
+
51
+ bool dynamic_library::loaded () const
52
+ {
53
+ return !m_handle;
54
+ }
55
+
56
+ dynamic_library::operator bool () const
57
+ {
58
+ return loaded ();
59
+ }
60
+ }
Original file line number Diff line number Diff line change
1
+ #include < string>
2
+
3
+ namespace utils
4
+ {
5
+ class dynamic_library
6
+ {
7
+ void *m_handle = nullptr ;
8
+
9
+ public:
10
+ dynamic_library () = default ;
11
+ dynamic_library (const std::string &path);
12
+
13
+ ~dynamic_library ();
14
+
15
+ bool load (const std::string &path);
16
+ void close ();
17
+
18
+ private:
19
+ void *get_impl (const std::string &name) const ;
20
+
21
+ public:
22
+ template <typename Type = void >
23
+ Type *get (const std::string &name) const
24
+ {
25
+ Type *result;
26
+ *(void **)(&result) = get_impl (name);
27
+ return result;
28
+ }
29
+
30
+ template <typename Type>
31
+ bool get (Type *&function, const std::string &name) const
32
+ {
33
+ *(void **)(&function) = get_impl (name);
34
+
35
+ return !!function;
36
+ }
37
+
38
+ bool loaded () const ;
39
+ explicit operator bool () const ;
40
+ };
41
+ }
Original file line number Diff line number Diff line change @@ -198,7 +198,7 @@ if(WIN32)
198
198
target_link_libraries (rpcs3 avformat.lib avcodec.lib avutil.lib swresample.lib swscale.lib png16_static ${wxWidgets_LIBRARIES} ${OPENAL_LIBRARY} ${ADDITIONAL_LIBS} )
199
199
else ()
200
200
target_link_libraries (rpcs3 ${wxWidgets_LIBRARIES} ${OPENAL_LIBRARY} ${GLEW_LIBRARY} ${OPENGL_LIBRARIES} )
201
- target_link_libraries (rpcs3 libavformat.a libavcodec.a libavutil.a libswresample.a libswscale.a png16_static ${ZLIB_LIBRARIES} ${ADDITIONAL_LIBS} )
201
+ target_link_libraries (rpcs3 libavformat.a libavcodec.a libavutil.a libswresample.a libswscale.a -ldl png16_static ${ZLIB_LIBRARIES} ${ADDITIONAL_LIBS} )
202
202
if (NOT APPLE )
203
203
target_link_libraries (rpcs3 vulkan glslang OSDependent OGLCompiler SPIRV)
204
204
endif ()
Original file line number Diff line number Diff line change 66
66
</ItemDefinitionGroup >
67
67
<ItemGroup >
68
68
<ClCompile Include =" ..\Utilities\AutoPause.cpp" />
69
+ <ClCompile Include =" ..\Utilities\dynamic_library.cpp" />
69
70
<ClCompile Include =" ..\Utilities\Log.cpp" >
70
71
<PrecompiledHeader >NotUsing</PrecompiledHeader >
71
72
</ClCompile >
363
364
<ClInclude Include =" ..\Utilities\BEType.h" />
364
365
<ClInclude Include =" ..\Utilities\BitField.h" />
365
366
<ClInclude Include =" ..\Utilities\BitSet.h" />
367
+ <ClInclude Include =" ..\Utilities\dynamic_library.h" />
366
368
<ClInclude Include =" ..\Utilities\event.h" />
367
369
<ClInclude Include =" ..\Utilities\geometry.h" />
368
370
<ClInclude Include =" ..\Utilities\GSL.h" />
Original file line number Diff line number Diff line change 854
854
<ClCompile Include =" Emu\PSP2\Modules\sceVoiceQoS.cpp" >
855
855
<Filter >Emu\PSP2\Modules</Filter >
856
856
</ClCompile >
857
+ <ClCompile Include =" ..\Utilities\dynamic_library.cpp" >
858
+ <Filter >Utilities</Filter >
859
+ </ClCompile >
857
860
</ItemGroup >
858
861
<ItemGroup >
859
862
<ClInclude Include =" Crypto\aes.h" >
1624
1627
<ClInclude Include =" ..\Utilities\sync.h" >
1625
1628
<Filter >Utilities</Filter >
1626
1629
</ClInclude >
1630
+ <ClInclude Include =" ..\Utilities\dynamic_library.h" >
1631
+ <Filter >Utilities</Filter >
1632
+ </ClInclude >
1627
1633
</ItemGroup >
1628
1634
</Project >
You can’t perform that action at this time.
0 commit comments