bind/function/??? - accessing global function static type with runtime dll
I'm interfacing with several 'C' dynamic link libraries each with the same interface. The appropriate libraries get loaded/unloaded at run time. The following is an attempt create a wrapper that returns a function pointer of the proper static type as declared for the 'C' functions. //------------------------------ class DLL { HMODULE mDLLHdl; public: ~DLL(){ FreeLibrary( mDLLHdl ); } DLL( const std::string& aDLLName ) :mDLLHdl( LoadLibrary( aDLLName.c_str() ) ){} operator bool()const{ return mDLLHdl; } operator HMODULE()const{ return mDLLHdl; } template< typename TFnc > TFnc Fnc( const std::string& aName, TFnc )const { return (TFnc)GetProcAddress( mDLLHdl, aName.c_str() ); } }; //------------------------------ With: typedef int (FAR WINAPI *FARPROC)(); FARPROC GetProcAddress( HMODULE hModule, // handle to DLL module LPCSTR lpProcName // function name ); For example, it's used as follows: //------------------------------ // declared in an included header with extern "C" int DoAttach( const char* aName, int attachMode ); DLL lSomeDll( "Some.dll" ); boost::function0<int> lFnc = boost::bind( lSomeDll.Fnc( "DoAttach", DoAttach ), "Name", 123 ); //------------------------------ Which compiles fine, but results in unresolved external symbols errors during linking for 'DoAttach' in this example. I can force-link and run the resulting executable w/out problem. Is there a way to get the type of the function without the compiler needing to use the function pointer itself? Thanks, Jeff
participants (1)
-
Jeff Flinn