Thunk and ATL Thunk?
Asked Answered
R

1

5

Can someone explain to me what a Thunk is?

and an ATL Thunk?

I know a thunk has something to do with the vtbl and execution of code to find the right function pointer. Am I right?

Refrigerator answered 25/7, 2010 at 14:22 Comment(1)
Here's a Stack Overflow question about thunks: https://mcmap.net/q/143397/-what-is-a-39-thunk-39. So, unless narrowed to asking about ATL thunks only (for example "How thunks are used in ATL?"), your question should be closed as a dupe, I think.Duplet
O
7

It is a generic term for a piece of adapter code that fundamentally changes the execution environment. I saw it first being used during the 16-bit to 32-bit Windows transition, a thunk was used to allow code that was running in 16-bit mode to call 32-bit code.

Something similar for ATL thunks. It knows how to turn a Windows callback, a pure C execution environment with nothing but a window handle to distinguish the context, into a virtual method call on a class object. The thunk takes care of mapping the window handle to the ATL class instance that wraps it, and translate the message number to the corresponding virtual method.

Orinasal answered 25/7, 2010 at 14:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.