For the first time the other day, I was in a position where I needed to use boost::bind with a plain Windows function. Having used COM objects with shared_ptr in the past, I remembered that the BOOST_MEM_FN_ENABLE_STDCALL define is required to get mem_fn to work with stdcall functions. Before jumping in with bind, I checked if there was something similar for it as they’re both concerned with calling conventions and function pointers. This turned up BOOST_BIND_ENABLE_STDCALL which I dutifully defined and went on my way.
#define BOOST_BIND_ENABLE_STDCALL #include <boost/bind.hpp> ... boost::bind(&ShellExecute, ...);
And then I compiled:
bind\bind_cc.hpp(22) : error C2995: 'boost::_bi::bind_t<R,R(__stdcall *)(void),boost::_bi::list0> boost::bind(R (__stdcall *)(void))' : function template has already been defined bind\bind_cc.hpp(17) : see declaration of 'boost::bind' bind\bind_cc.hpp(31) : error C2995: 'boost::_bi::bind_t<R,R(__stdcall *)(B1),_bi::list_av_1<A1>::type> boost::bind(R (__stdcall *)(B1),A1)' : function template has already been defined bind\bind_cc.hpp(26) : see declaration of 'boost::bind'
Where did the duplicate definitions come from? The pre-processed output showed the normal definitions and then the explicit __stdcall ones, so I rebuilt the project in case it was just one of those quirks. The result was identical. As they were apparently duplicate definitions, I removed the define and tried again… and it compiled fine.
Then the facepalm moment. I’d changed the default calling convention of the project to stdcall earlier, which made the normal bind definitions stdcall to begin with. Sometimes I really am a bit of a numpty.
Moral of the story:
If you’re compiling with the /Gz flag in Visual Studio, don’t define BOOST_BIND_ENABLE_STDCALL because bind is already stdcall compliant.