
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<int (int)> func; func = proc_address<int (int)>(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

Alexander Lamaison wrote:
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<int (int)> func; func = proc_address<int (int)>(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
IIRC MSVC has problem with the int() notation try the portabel function usage: boost::function<int,void> or something -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

On Wed, 10 Mar 2010 20:51:38 +0100, joel falcou wrote:
Alexander Lamaison wrote:
template<typename Signature> boost::function<Signature> proc_address( hmodule hmod, const std::string& name) { return boost::function<Signature>(GetProcAddress(hmod, name.c_str()); }
IIRC MSVC has problem with the int() notation try the portabel function usage:
boost::function<int,void> or something
Unfortunately, I can't write proc_address<int, int> because it only has the single Signature template paramter. I notice that the boost 'portable syntax' would be boost::function*X*<int, void, etc...>. I don't have numbered versions of proc_address. Is this what I need to get it to work? Alex

Alexander Lamaison wrote:
Unfortunately, I can't write proc_address<int, int> because it only has the single Signature template paramter. I notice that the boost 'portable syntax' would be boost::function*X*<int, void, etc...>. I don't have numbered versions of proc_address. Is this what I need to get it to work?
I think so -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

On Wed, Mar 10, 2010 at 1:09 PM, joel falcou <joel.falcou@lri.fr> wrote:
Alexander Lamaison wrote:
Unfortunately, I can't write proc_address<int, int> because it only has the single Signature template paramter. I notice that the boost 'portable syntax' would be boost::function*X*<int, void, etc...>. I don't have numbered versions of proc_address. Is this what I need to get it to work?
I think so
That should not be necessary, VS2k5 supports the modern usage just fine. I actually have code that does exactly what you are trying to do that works just fine.

On Wed, 10 Mar 2010 21:31:06 -0700, OvermindDL1 wrote:
On Wed, Mar 10, 2010 at 1:09 PM, joel falcou <joel.falcou@lri.fr> wrote: Alexander Lamaison wrote:
Unfortunately, I can't write proc_address<int, int> because it only has the single Signature template paramter. I notice that the boost 'portable syntax' would be boost::function*X*<int, void, etc...>. I don't have numbered versions of proc_address. Is this what I need to get it to work?
I think so
That should not be necessary, VS2k5 supports the modern usage just fine. I actually have code that does exactly what you are trying to do that works just fine.
Would you be able to post a snippet showing the declaration? Thanks. Alex
participants (3)
-
Alexander Lamaison
-
joel falcou
-
OvermindDL1