Boost logo

Boost Users :

Subject: Re: [Boost-users] Windows API callback, using boost::bind
From: John Dlugosz (JDlugosz_at_[hidden])
Date: 2010-10-29 13:31:10


> The common approach is to generate code that translates from the
> thiscall calling convention to stdcall.
>
> There might be third party libraries that can do this, but I'm unsure
> if
> it's possible at all on x64, if that matters.

I have a free library that does this for 32-bit code. It's fairly easy to translate from "thiscall" calling convention to "stdcall". The same trick won't work for x64. Generating an actual call to re-push the arguments needs to know more details about the number and type of arguments! However, a typed thunk generator could be crafted for the specific signature needed. You also need to allocate the thunk's memory in a page that was VirtualAlloc'ed to hold code (in 32-bit code you can just disable the feature), which complicates management of thunks as value objects. I've not gotten around to it, and don't have an immediate need for it. But I'd be happy to give some pointers if someone were writing such a thing.

>
> The other common solutions is to have a global pointer to your instance
> and use that from a static member function,

For real things I've encountered, the number of callbacks needed is limited to a small value known at compile time. Using a fixed global or a small pool of individually written global wrappers is much simpler than anything else. Hmm, using a numeric template argument it would be trivial to create a "pool" of any size N, without excessive source code.

-

TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.


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