I'm trying to write a little wrapper round Windows GetProcAddress (dlsym
equivalent?) that takes a function name by string, loads it dynamically and
returns it as a boost::function. I'm having trouble getting my code to
accept the same type of signatures as boost::function.
E.g.:
template<typename Signature>
boost::function<Signature> proc_address(
hmodule hmod, const std::string& name)
{
return boost::function<Signature>(GetProcAddress(hmod, name.c_str());
}
Where GetProcAddress returns a int (*)() which you cast to the function
signature you're expecting. The problem is that when I call:
boost::function func;
func = proc_address(hmod, "GetKeyboardInfo");
The compiler (MSVC 2005) complains about a ) after the int:
error C2144: syntax error : 'int' should be preceded by ')'
error C2563: mismatch in formal parameter list
Am I trying to reuse boost::function the wrong way?
I also tried making a functor instead but I have no idea what to put as the
parameter list for operator():
template<typename Signature>
class dynamic_function
{
public:
dynamic_function(hmodule hmod, const std::string& name)
: m_func(GetProcAddress(hmod, name.c_str())) {}
operator()(...what goes here?...) { return m_func( ... what ... ); }
private:
boost::function<Signature> m_func;
};
Any help is greatly appreciated.
Alex