Boost logo

Boost Users :

From: Douglas Gregor (doug.gregor_at_[hidden])
Date: 2005-03-14 10:36:01


On Mar 10, 2005, at 12:16 PM, Olenhouse, Jason wrote:
> I'm trying to pass a member function pointer around to the Windows
> Service Control Manager through
> Windpws API functions, but I think I'm having troubles with the
> __stdcall convention.
>
> I'm using MSVC 7.1.3088. For brevity I've left out information, but I
> think this is enough to go on:
>
> __ExampleClass.h__
> class ExampleClass
> {
> protected:
> void Setup( void );
> void __stdcall ServiceMain( DWORD dwArgc, LPSTR *lpszArgv );
> LPSERVICE_MAIN_FUNCTION m_fServiceMain;
> };
>
> __ExampleClass.cpp__
> void ExampleClass::Setup( void )
> {
> boost::function<void ( DWORD, LPSTR * )> f2 = boost::bind(
> boost::mem_fn( &ExampleClass::ServiceMain
> ), this, _1, _2 );
> m_fServiceMain = f2.target<void ( DWORD, LPSTR * )>( );

There seem to be two issues here.

The first issue is that function::target() does something different
than what you're trying to do. function::target<T>() will return a
pointer to a T. If the actual object stored by the instance of
boost::function has type T, you get the pointer; otherwise, you get a
NULL pointer. If the code above had worked, m_fServiceMain would get a
NULL pointer, because the type of the bind expression in the line
before it is something big, ugly, and very hard to reproduce (but it
can't be void(DWORD, LPSTR*)).

The second issue is that void(DWORD, LPSTR*) is probably not the type
you want, because it is not the type of a function object. To extract a
function pointer, you would use, e.g., "void (*)(DWORD, LPSTR*) ". I'm
sure the __stdcall needs to be in that type somewhere, but I don't know
where it would go :(

        Doug


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net