Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#if !defined (LIBRARY_HPP__INCLUDED) #define LIBRARY_HPP__INCLUDED #pragma once #include <windows.h> #include <string> namespace winapipp { struct Library { Library(std::basic_string<TCHAR> const& file) : m_module(::LoadLibrary(file.c_str())) { if (!m_module) throw std::invalid_argument("invalid library file"); } virtual ~Library() { ::FreeLibrary(m_module); } public: template<typename function_type> inline function_type load_function(std::string const& name) { function_type temp(static_cast<function_type>(::GetProcAddress(m_module, name.c_str()))); if (temp == NULL) throw std::invalid_argument("unknown function specifier"); return temp; } private: ::HMODULE m_module; }; }; // winapipp #endif // LIBRARY_HPP__INCLUDED |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
#if !defined (LIBRARY_HPP__INCLUDED) #define LIBRARY_HPP__INCLUDED #pragma once #ifdef _WIN32 #include <windows.h> #else // not Windows (r) OS #include <dlfcn.h> #endif // OS #include <string> namespace winapipp { struct Library { Library(std::string const& file) #ifdef _WIN32 : m_module(::LoadLibraryA(file.c_str())) #else // not Windows (r) OS : m_module(::dlopen(file.c_str(), RTLD_LAZY)) #endif // OS { if (!m_module) throw std::invalid_argument("invalid library file"); } virtual ~Library() { #ifdef _WIN32 ::FreeLibrary(m_module); #else // not Windows (r) OS ::dlclose(m_module) #endif // OS } public: template<typename function_type> inline function_type load_function(std::string const& name) { #ifdef _WIN32 function_type temp(static_cast<function_type>(::GetProcAddress(m_module, name.c_str()))); #else // not Windows (r) OS function_type temp(static_cast<function_type>(::dlsym(m_module, name.c_str()))); #endif // OS if (temp == NULL) throw std::invalid_argument("unknown function specifier"); return temp; } private: #ifdef _WIN32 ::HMODULE m_module; #else // not Windows (r) OS void* m_module; #endif // OS }; }; // winapipp #endif // LIBRARY_HPP__INCLUDED |
Zitat von »"Deviloper"«
So, damit ist dein Traum erfüllt.
Anonymous
unregistriert
Anonymous
unregistriert
Anonymous
unregistriert
Zitat
Einfaches C++-Interface um das Arbeiten mit Dlls zu vereinfachen.
Zitat
C eine Library laden müsste könnte ich jetzt genau hier sehen welche Methoden ich brauche
Quellcode |
|
1 2 3 4 5 6 |
struct Library { // Methoden public: // mehr Methoden } |
Werbeanzeige