Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-10-30 07:14:01


From: "Philip Nash" <philip.nash_at_[hidden]>
> I'm using MSCV (6) and am unable to bind to a function that is declared as
> using the __stdcall calling convention (eg, any Windows API function). I
get
> a compiler error along the lines of, "cannot convert parameter 1 from
> <function ptr not using __cdecl> to <function ptr using __cdecl>"
>
> Should this be possible? If not is there a workaround (other than creating
a
> forwarding function by hand for every __stdcall function I want to bind
> to!)?

It's possible. Treat the __stdcall function as a function object and use the
general bind<R>(f, ...) syntax.

Here's an example from my code:

class dialog
{
public:
 HWND get() const;
};

bool isDialogMessage(MSG * msg)
{
 std::set<dialog *> const & instances = ::instances();

 // see if the message is for a modeless dialog box

 return std::find_if(instances.begin(), instances.end(),
boost::bind<BOOL>(::IsDialogMessage, boost::bind(&dialog::get, _1), msg)) !=
instances.end();
}

HTH

It would probably be an interesting extension to add the necessary __stdcall
overloads to bind but this is a dangerous path. :-)

--
Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk