Active Template Library - ATL

  • Describe the USES_CONVERSION macro
    ATL provides macros for various kinds of conversion, the most commonly used ones being string conversion macros such as A2W and OLE2CA. In order for one to convert between Multibyte and Wide char strings, one needs to allocate space on the heap and call the MultiByteToWideChar or WideCharToMultiByte APIs. This requires extra code and if this conversion needs to be done in many places, it leads to code bloat and slower speed due to the heap allocations and deletions. To circumvent this problem, ATL introduced macros that perform the necessary conversions. These allocate space on the stack to temporarily hold the converted strings. Since these use calloc(), the allocated space is automatically freed when the function exits (and hence its stack frame is destroyed). Since temporary allocations are necessary, these macros need to compute the size required for the requested allocations. Among other things, USES_CONVERSION declares a variable to hold the size of the requested allocation.

  • What are the effects of setting the _ATL_MIN_CRT preprocessor flag?
    If this pre-processor flag is set, ATL overloads the malloc/free, new/delete operators to call into the HeapAlloc/HeapFree Win32 calls, avoiding calls into the CRT. This permits the app not to link with the CRT, keeping the application size small.

  • When creating MTA objects, what are the necessary design considerations?
    In a multi-threaded apartment, the RPC subsystem will permit multiple clients to concurrently access the same object. In order to protect the integrity of the state of the server object, MTA objects have to use synchronization objects (like critical sections, events and semaphores).

  • Name ATL helper classes that can be uses while designing MTA objects?

  • What are shim classes?

  • What are the functional differences between _bstr_t and CComBstr?
    CComBstr is a leaner and meaner variety of _bstr_t. It does not perform reference counting, nor does it "cache" ANSI strings to speed up conversions.

  • Why are the ATL methods used as Windows callback procedures declared as static?

  • Describe STRICT type checking
    By turning on the STRICT preprocessor flag, you are preventing the application from carelessly typecasting between similar types. For example, HWND and HDC are both handles. Carelessly passing an HWND to a function that expects an HDC will be permitted by the compiler, unless the STRICT flag is turned on. By using the STRICT flag, the compiler renames each type, thus forcing the user to explicitly typecast variables before using them interchangably. This makes the code more readable and maintainable, not to mention the mitigation of debugging headaches.

  • Why does ATL employ window thunks?