ATL Q&A

  1. The list of items in Class View is wrong. How to make it right?:

    Details

    Locate <projectname>.ncb file in project folder. Delete it, open project then. NCB-file will be recreated and Clas View would have list of items consistent with a project. Note: NCB-file stands for No Compile Browser file.

  2. When making MinDependancy build a project link error 'unresolved external symbol _main' comes out. What does it mean?:

    Details

    MinDependancy build presumes that you are not using run-time C functions defined in msvcrt.dll. MinDependancy build includes _ATL_MIN_CRT constant to exclude msvcrt.dll from the build. Meanwhile atl.dll is statically linked to the build making for you not necessary to distribute the DLL as separate file. However if you are using C run-time functions in the project the error will be generated.The second reason is that you are using STL support that is also dependant on msvcrt.dll. Therefore there are two ways to avoid the error. First is to replace C run-time functions with their C counterparts and not to use STL. Second way is more frequently used, , just remove _ATL_MIN_CRT from project setting. It makes inclusion of msvcrt.dll into the release build and makes size of the build will bigger.

  3. What is the difference between class and interface?:

    Details

    The COM-term interface is actually a narrower definition of C++ class. An interface is a class, but not every class is an interface. An interface consist of a pure virtual functions only.

    Accordingly, the definition of IUnknown base COM-interface has only pure virtual functions:

    class IUnknown
    {
    public:
            __stdcall virtual HRESULT QueryInterface( REFIID riid, void ** ppvObject ) =0;
            __stdcall virtual ULONG AddRef()=0;
            __stdcall virtual ULONG Release()=0;
    }

  4. There are three types of messages in ATL - Window Messages, Command Messages and Notify Messages. What's the difference?:

    Details

    Window messages are regular messages sent by window in a response to a window event such as mouse click, window resize etc. The messages are "WM_" prefixed and have both number and name for practical use like: WM_LBUTTONDOWN. Window messages are handled by window message handler with signature:

    LRESULT MessageHandler( UINT uMsg, WPARAM wParam, LPARAm lParam, BOOL& bHandled);

    Command messages are sent by controls such as Button, Edit, List etc to a parent window that contains it. Intrinsically the control are Win32 child window classes and therefore Command messages are also window messages. Unlike regular Window messages that sent messages to window itself, command messages are sent to parent window that holds child window representing controls. The function signature for command messages handling is following:

    LRESULT CommandHandler( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled );

    Third kind of messages are notify messages that are sent by Common Control such as List View, Tree View, Header View etc. These messages are generally more complicated and have a pointer to a structure that contains information about a message. Notify handler function signature:

    LRESULT NotifyHandler( int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

    Think about an analogy between containment of ATL/ActiveX control in a container, messaging between control and container on COM level and more simple containment and messaging between parent window and control that are hosted by the window.

  5. Is there a limit on BSTR ( _bstr_t, CComBSTR ) string length?:

    Details

    Yes, by design BSTR and related _bstr_t, CComBSTR types have a limit on length of string. Unlike C-strings BSTR-type is length-prefixed. Content of first four bytes of BSTR-type reflects BSTR-length. Maximum number allocated in 4 bytes is 232. This is approximately 4 GB. Having that each symbol in BSTR takes 2 bytes, the maximum length of BSTR would be 2 GB ( 2,147,483,648 is an exact fugure ).

  6. What is the difference between stock and ambient properties?:

    Details

    Stock properties are properties of a control. Ambient properties are properties of a container. Stock properties can be changed by both control and by container. Ambient properties can be changed by container only and read-only by a control. There are 24 stock properties that include control background color, font, caption etc. All stock properties are public data members of CComControl class. Control can read 17 ambient properties exposed by container with functions of CComControl class. Stock properties can be extended with arbibrarily number of custom properties and ambient properties can be extended with arbitrarily number of extended properties. The use of ambient properties comes into play when control needs to adjust its appearance to container's appearance.

© (c) 2001, Stanislav Malevanny