C++ Essential Questions and Answers and C++ HOWTO

Copyright © Marcel Lambert.

C++ Essential Questions and Answers

  1. What are 24x24 and 48x48 icons used for?

    Details

    Both icons sizes are new in Windows XP. Their use is the following:

    • 24x24 (true color) icon is used in start menu (right-side panel).
    • 48x48 (true color) icon is used as thumbnail image in Windows Explorer. Notice that in Window 2K it was usually enough to have 32x32, and 16x16 16-color icons for your application. Windows XP had dramitically changed this picture, and MFC application icon generated by default with MFC application wizard has 9 icons (16x16, 32x32, 48x48 with 16, 256, 16 millions colors) instead of two.

  2. What are the differences between Windows XP and Windows 2K icons?

    Details

    From programming perspective, Windows 2K requires just two icons: 32x32 (16-color) and 16x16 (16-color). Look at icons that Visual Studio 98 provides for MFC applications by default:

    Windows XP uses, at least, 9 icons instead of 2 icons in Windows 2K. Compare these 9 icons that VS.NET (2003) provides by default for MFC application with the picture above.

    Making icons for Windows XP is much more elaborate process then for Windows 2K, and frequently requires a professional icon designer to make commercial product successful. Here are some new issues to consider when making Windows XP icons:

    • 9 icons (16x16, 32x32, 48x48 with 16, 256, 16 millions colors) instead of 2.
    • New 48x48 size used for thumbnail view in Windows Explorer. There is also new 24x24 size used for Start menu (right side) and for application toolbars.
    • Icons should be rendered in perspective (not for file types), have light source coming from upper-left, be angle-rounded, use special Windows XP palette.
    • Windows XP icons are really up to 32-it color icons with 24-bits for palette and 8 bits for alpha channel.

    Notice that while Visual Studio (98) Image Editor default palette is 16-color palette, VS.NET Image Editor default palette has 256 colors.

  3. Where 16x16 icons are used? Where 32x32 icons are used?

    Details

    Both in Window Windows 2K and XP, 16x16 icons are used as/at:

    1. Application title bar.
    2. Start/Programs (right side).
    3. Window Explorer's small icons view (also list, details views).
    4. System tray controls.
    5. Status bar (when minimized).
    6. Add/Remove programs list.

    32x32 icons are used as/at:

    1. Window Explorer's large icons (also in thumbnails view).
    2. Desktop application icon.
    3. Default application about box.
    4. Alt+Tab.
    5. Start menu (left panel).

  4. Frequently, an application has many icon resources. What icon Windows selects as application icon? As fyle type icon?

    Details

    Windows selects the icon with lowest resource ID as application icon. You can see what icon has lowest resource ID in resource.h.

    When an application registeres its own file type in registry, it can setup DefaultIcon registry key under HKCR\<applicationtype> and specify file type icon by setting <iconnumber>:

    Value Name: (Default)
    Value Key: <name>.exe, <iconnumber>

    In this case icon number is not a resource ID, but one-based number of icon resource listed in RC file counted from the begining of the icon resources list!

  5. How to enable Windows XP control styles in C++ application?

    Details

    Windows XP introduced new control styles with rounded angles and dynamic appearance. Compare:

    To use XP styles you should tell your application to use version 6 of comctl32.dll instead of version 5. Notice that Windows XP shipped with both versions, but Windows 2K does not have version 6 (and, moreover, version 6 is not redistributable). How, then, my Windows XP application would know what version of DLL to load? In fact, XP application uses new resource file with extension MANIFEST to tell Windows XP application to load version 6 of comctl32.dll. In short, just two steps are required to enable Windows XP stypes:

    • When buiding application with MFC wizard check option "Common Control Manifest" in Advanced Features. By default, XML file with .MANIFEST extension will be generated and placed into RES directory.
    • Reference manifest file in RC file:

      CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "res\\XPStyles.manifest"

    That's it. You don't even need to derive your dialog classes from CDhmlDialog to use Windows XP control styles!

    Interestigly, the locations of version 5 and version 6 of comctl32.dll on Windows XP are different. While older version located in %windir%/system32, the newer version located inside %windir%/WinSxS.

  6. How to obtain Win32-style HWND handle from MFC window class, and having a HWND handle obtain a pointer to CWnd?

    Details

    You might need a "conversion" of CWnd pointer to HWND handle when Win32 funtions are used in MFC application. Because every MFC window class derived from CWnd and CWnd has m_hWnd member, the answer to the first part of the question is to use m_hWnd. As simple as that!

    To obtain CWnd from HWND, there is a little bit more complicated standard solution: use FromHandle member function of CWnd, which returns pointer to CWnd provided that HWND handle passed as an argument.

  7. In MFC, when DDX exchange is used, what function to use to update dialog class data from dialog controls data (which are visible to user)?

    Details

    To update dialog class data from dialog UI data use:

    UpdateData(TRUE);

    To make an update in opposite direction, i.e. update values of controls in dialog UI from dialog class data, use:

    UpdateData(FALSE);

  8. What are the benefits of explicit (dynamic) linking comparing to implicit linking?

    Details

    Recall that dynamic linking relies on calling two functions: LoadLibrary, which returns a handle to a DLL, and GetProcAddress, which returns an address of a function having a DLL's handle. There are two major benefits for dynamic linking:

    • There is no need in LIB file. In opposite, while doing implicit linking you should statically link LIB satellite of a DLL in project settings.
    • Dynamic linking can dramatically reduce memory that a program takes. For example, if a user of your program can select with UI one module (DLL) at a time from a list of many optional DLLs the choice of dynamic linking would be right. Why? This is because once a program is started all implicitly linked DLL are loaded into memory even if they would have not be ever used. In opposite, a library linked dynamically loaded into memory when a program really needs it, and unloaded (it is programmer responsibility not to forget it!) when there is no longer need in it.

      Notice that resource-only DLLs are, in fact, always loaded dynamically. They do not have LIB-file (/NOENTRY linker option must be specified to say linker that a DLL does not have functions). Such DLLs are loaded simply with a LoadLibrary call, and subsequent calls to functions like LoadResource, LoadString etc, which are used to load resources required.

  9. What is most simple method to generate a list, say 100, of GUIDs?

    Details

    You might need bulk GUID generation when, for example, you've decided to use GUID as registration code for your program, and need to generate a lot for different users. The solution is to use uuidgen command line utility:

    uuidgen -n100 > c:\guids.txt

    The output is like:

    30295ce5-a175-4a83-84b1-d6fa12b24bb6
    853b045e-d02f-4d98-8119-e32f189cd7af
    6fe48533-1ea1-46a5-aecc-7db2c03734b1
    45131cd4-1b46-4b07-bb6f-277ccca0af40
    177e257f-42fc-415b-a891-3fd768040f9f
    ...

    Notice that uuidgen.exe can be located under:

    %programfiles%\Microsoft Visual Studio .NET 2003\Common7\Tools (VS.NET 2003)
    %programfiles%\Microsoft Visual Studio\Common\Tools (VS'98)

  10. What MFC class can be used to implement directory picker functionality?

    Details

    Unfortunately, MFC does not provide a separate class for directory picker (or folder picker). Interestingly, this kind of UI is pretty popular. Directory picker is a feature of WinZip, WinZip Self-Extractor etc. You can find it even in Microsoft VS.NET 2003, written in C++: go to File/New/New Project, then click on Browse button to bring up Project Location, which is directory picker UI!

    So, how to implement directory picker in your own program? There are 2 solutions:

    • Modify standard MFC CFileDialog, which by default provides functionality for File Open, Save As actions, by using custom dialog template or/and dialog hook procedure.
    • Write your own directory picker class using SHBrowseForFolder function.

  11. How to make transparent areas in ICO file?

    Details

    In C++ project, you can use simple Image Editor that bundled with VS.NET, and available also in previous versions. A trick to make image backgroung color transparent, or other words force this color to take destination colors, takes two steps:

    • Paint designated areas with a special system color called "screen color".
    • Repeat previous step for all icon images (or devices).

    Here are futher details. Click on the special "screen color" icon in Image Editor palette, which shown as green monitor.

    The foreground rectangle takes this image. Then, use toolbox instrument (fill with color) to fill transparent areas with screen color.

  12. How to make an icon file for Visual C++ project?

    Details

    Standard icon file is composed of several bitmap files (BMP). The number of files depend on operation system you are using.
    Generally you need source BMP files and a program tool to make a single ICO file. You can download trial versions:

    Icon Book (version 4.22 at the time of writing)
    GIF Movie Gear (version 4.02 at the time)

    First tool is an icon browser, it also provides sample icon collections. The secong tool converts a set of images into a single ICO file. Here are the simple steps to create an icon:

    • Open dll, exe etc file containing icons (i.e. shell32.dll) in IconBook. IconBook shows all images for an icon in separate window. For example, if your OS is Windows XP and you choose an icon, the window shows 12 separate images depending on image size an color depth:

      48x48, 32x32, 24x24, 16x16 (24-bit color)
      48x48, 32x32, 24x24, 16x16 (16-bit color, or 256 colors)
      48x48, 32x32, 24x24, 16x16 (4-bit color, or 16 colors)

    • Open Movie Gear (you can start from any icon file).
    • In IconBook choose an image of necessary size/color depth and copy/paste it into Movie Gear. Choose next image of different size/color depth and copy/paste it too.
    • If sure that you have all required images save the set of Movie Gear images as ICO file.

    Now you can use ICO file in Visual C++ project.

  13. What is the matter with implicit and old-style casts? When and why C++ casts, such as static/dynamic, reinterpret, should be used instead?

    Details

  14. How to make DWORD (32-bit value) out of two WORDs (16-bit values)?

    Details

    This operation is opposite to extracting low-word/high-word parts from DWORD value performed by LOWORD, HIWORD macros. One example when you might need this conversion is to persist application hot keys into the registry. In fact, registry has REG_DWORD type, but does not have a type for WORD. On the other hand, if you use CHotKeyCtrl control you would extract hotkey value by the code like this:

    WORD wVirtualKey;
    WORD wModifier;
    m_ctlHotKey.GetHotKey(wVirtualKey, wModifier);

    Notice that wVirtualKey and wModifier are both WORD values. Naturally, it is convenient to store in registry one value instead of two. The following macros gives the answer:

    DWORD dwValue = MAKELONG(<low-order word>, <hi-order word>);

  15. In MFC, how to get a pointer from one property page to another?

    Details

    This task might be demanding when you need, for example, update controls state in one property page immediately after changes were made in another property page.The answer is to call member function CPropertyPage::QueryPages in the controling page and intercept PSM_QUERYSIBLINGS related event in the listening page. In MFC, another words, message map should be updated with new element:

    ON_MESSAGE(PSM_QUERYSIBLINGS, OnQuerySiblings)

    Notice that it is logical to guess that for this purpose one simply should use a pointer to another property page. Seeing following picture, you can futher suggest that if CPropertyPage2 has back pointer to CPropertySheet, which aggregates property pages, this pointer can be used for navigation to CPropertyPage1.



    Interestingly, MFC does not provide member functions/properties to get a back pointer or directly obtain a pointer to page of interest. The CPropertyPage::QueryPages should be used instead.

  16. I need to make a backup of Visual C++ development files. What files can be deleted (or skipped) during backup?

    Details

    .PCH files can eat up more then 50-60% of hard disk space taken by your VC++ project files. Likely the next biggest disk space eaters are .BSC, .SBR, .PDB, .IDB, .NCB, and .OBJ files. If you systematically backup your project files with these unnecessary files, you are wasting about 75-80% of your space on backup media!

    You can find/delete these files manually, or you can make a batch file with following lines to delete redundant files in root project folder, release, and debug folders correspondingly:

    for %%c in
    (*.ncb *.opt *.aps *.clw *.dsw *.dep *.tlh *.tli)
    do del %%c

    for %%c in
    (*.pch *.idb *.obj *.res *.dep *.tlh *.tli)
    do del %%c

    for %%c in
    (*.pch *.idb *.pdb *.sbr *.bsc *.obj *.res *.ilk *.map *.pbi *.pbt *.pbo *.tlh *.tli)
    do del %%c

  17. How C-strings relate to C/C++ arrays?

    Details

    C-strings are C/C++ character arrays. This is an important notion sometimes missed by novice programmers. C/C++ does not have a special fundamental data type for C-strings. In practical terms, one of the most frequenly features of C/C++ arrays used with C-strings is that the name of array is also a constant pointer to the first element in array (since arrays are zero-based, it is actually a pointer to its zero member).

    As an example, consider the strcpy function signature:

    char* strcpy(char* szDestination, const char* szSource);

    We make a routine copy like this:

    char szSource[] = "Source";
    char szDestination[100];
    strcpy(szDestination, szSource);

    Did you notice that you just used array name "szSource" as argument in function, which has const char* type. Again, this is because the name of C-string is also a constant pointer!

  18. When reinterpret_cast is used and how it is different from dynamic_cast (static_cast)?

    Details

  19. What is the difference between dynamic_cast and static_cast?

    Details

    dynamic_cast and static_cast are both used for downcasts in a class hierarchy, and can be used, albeit it is not necessary, for upcasts (generally, upcasts are implicit casts). Albeit, static_cast and dynamic_cast are close in meaning and use, they are different when dealing with polymorphic base classes (i.e. classes that have virtual functions). If base class is polymorphic:

    • dynamic_cast should be used for downcast while use of static_cast is not recommended (as not safe).
    • dynamic_cast makes run-time check (static_cast does not). Notice that to enable run-time check /GR compiler option should be set (instead of /GR- default option).
    • dynamic_cast can be used only if base class is polymorphic (otherwise compiler generates an error). static_cast can be used both with polymorfic and non-polymorfic classes.

  20. What is the length and the size of the string?

    TCHAR szString[] = _T("Armadillo");

    Details

    The length is 10 (9+1). The count includes also NULL-terminating string ('\0'), which accounts for one additional character regardless of _UNICODE is defined or not.

    If _UNICODE is defined the size is 20 bytes because _UNICODE character takes 2 bytes. If _UNICODE is not defined the declaration is equivalent to:

    char szString[] = "Armadillo";

    In this case, the size of szString is 10 bytes because ANSI character takes 1 byte.

  21. Why const keyword is frequently used to prefix paramer type in many standard functions for C-strings manipulation e.g. strcpy, ctrcmp?

    Details

    These reasons are general, and C-strings function prototypes can demonstrate them. For example, the function to copy C-strings, strcpy, has a prototype:

    char* strcpy(char* pszDestination, const char* pszSource);

    By declaring the second parameter as const, two results are achived:

    • The function cannot change corresponding parameter in the caller function when called function returns. This provides a level of safery for the caller function when it is necessary to have a guarantee that its parameters would not be changed. Recall that in C/C++ function can return values not only with explicit return statement, but also through the parameters in parameter list.
    • In a case when you, as a programmer, lack information about what parameter(s) is(are) input parameter(s) in a function, the const keyword brings indication that parameter in question is an input parameter.

  22. When creating a C++ class, what is the syntax for initializing its data members?

    Details

    Here is the sample to initialize two pointers to character 
    strings:
    
    class A
    {
    public:
            A(LPCTSTR lpszName, LPCTSTR lpszDesc = NULL) : 
                    m_lpszName(lpszName), m_pszDesc(pszDesc){}
            ~A();
    private:
            LPCTSTR m_lpszName;
            LPCTSTR m_lpszDesc;
    };
    
    The second pointer takes default value NULL if one value only is 
    passed to the constructor. Notice that constructor is suffixed
    by curly brackets without semicolon (function with a body is not
    required to be terminated by semicolon).
    
    or when constructor defined separately:
    
    class A
    {
    public:
            A(LPCTSTR pszName, LPCTSTR pszDesc = NULL);
            ~A();
    private:
            LPCTSTR m_lpszName;
            LPCTSTR m_lpszDesc;
    };
    
    A::A(LPCTSTR pszName, LPCTSTR pszDesc = NULL) : 
            m_lpszName(lpszName), m_lpszDesc(lpszDesc)
    {
    
    }
    
    Notice that it is not necessary to initiliaze data members inside 
    constructor body explicitly (e.g. m_pszName = pszName; 
    m_pszDesc = pszDesc).
    

  23. When to use _TCHAR (TCHAR), char types? _T (_TEXT), L macros? What is the difference between them correspondingly?

    Details

    _TCHAR (TCHAR) types, and _T(_TEXT), L macros are used for UNICODE builds only. Don't use these macros for non-UNICODE builds. If you are using UNICODE builds take notice of the following:

    • There is no difference between _TCHAR and TCHAR. They are both declare 2-byte character strings (wchar_t) for UNICODE builds and 1-byte character strings (char) for non-UNICODE builds. _TCHAR notation, however, is more frequently used in the MSDN (2003) documentation.
    • There is no difference between _T (_T is just the short form of _TEXT) and L macros for UNICODE builds. In fact, _T defined as L macro for these builds. They are both transform 1-byte character string to 2-byte character string. In non-UNICODE builds _T macro is removed, i.e. has no effect, during build process. Don't use L macro in non-UNICODE builds since an error will occur.
    • UNICODE builds are default builds in Visual Studio NET (2003) in opposite to non-UNICODE default builds in Visual C++ 6.0.

  24. How to reference path that contains quotes?

    Details

    The following sample is the answer:

    TCHAR szValue[80];
    lstrcpy(szValue, "\"C:\\Program Files\\Synaptex\\SSS\\SSLauncher.exe\" /startup");

    Notice that when path containing spaces should be passed to command line interpreter, it should be decorated with trailing double quotes.

  25. In MFC, what classes correspond to Check Box, Radio Button?

    Details

    You might have not expected it, but there are no separate classes for Check Box and Radio Button in MFC. In fact, these controls are of CButton type! Notice that Group Box is also managed by CButton class.

  26. What is the difference between an icon and bitmap?

    Details

    Icons are like bitmaps, but they are usually having more then one bitmap image inside with each of images used by different devices. Think about an application icon: the icon should point to the application in both views of Windows Explorer Small Icons/Large Icons, which use 16x16 and 32x32-icons respectively. If you'd place application shortcut on the desktop, 32x32 application icon will be used. 16x16 icon is used in the Start menu. As you can see, usually you need to provide for your application the same picture, but with different sizes. ICO-format lets have in one file these different images so that you delegate to Windows system to decide what image to use depending on the context.

  27. How to add custom icon - application icon - into the title bar of Wizard-generated Win32 application?

    Details

    When you create new Win32 project with "Win32 Application" wizard, you'd have standard 16x16 Win32 icon at the left of the title bar. If you'd place application shortcut on the desktop 32x32 icon will be used. Both icons are provided by Win32 system by default: a Win32 application can be as simple as to have only empty WinMain function. In the wizard-generated project there is no resouce file (RC), and naturally Resouce View is empty for a project. To add your own icon use the following steps:

    • Go to File/New and choose Resource Script. Usually you would choose <projectname> as the name for the resouce script. At this point non-empty <projectname>.rc and resource.h will be added to the project folder.
    • Compile project.
    • If you open Resource View you would not see resource folders, as you might expect from your MFC experience. Instead you would see <projectname>.rc folder in the right pane. To browse resources in the Resource View close VC IDE, launch it again and open Win32 project. You would see in the Resouce View <projectname> folder now. Since it is empty it expands to "No Resources".
    • Add new icon resource. Set ID for the resource, it is IDR_MAINFRAME usually. This ID Win32 is using by default for an application icon.
    • At first Image Editor has 32x32 icon. Draw it as you wish. Add 16x16 device and draw it too.
    • Compile.

  28. Why C++ compilers decorate DLL exported function names?

    Details

    C++ provides that one function can be declared with different parameter list within the same program. C++ calls this mechanism function overloading. To distinguish these declarations internally, C++ compilers decorate function names (generally different compilers decorate the same function names differently). Notice that name decoration (name mangling is another term) is a C++ feature, not C feature. If your program does not use function overloading you can tell compiler not to produce name decorations for functions by specifying extern "C" before the name of every exported function.

  29. What Win32 mechanism is used in VC IDE for recording/playing back user actions (macros), and for enabling context-sensitive help?

    Details

    Hooks.

  30. You'd set extended behavior and appearance of windows common control with 4 types of styles using CreateEx function. In particular, to create list view control you would use styles WS_*, WS_EX_*, LVS_*, LVS_EX_* setting dwExStyle, and dwStyle parameters of CreateEx. What is the placeholder for each of these styles: dwExStyle or dwStyle?

    Details

    Set normal styles - WS_* and LVS_* - in dwStyle (in any relative order), and extended styles - WS_EX_*, LVS_EX_* - in dwExStyle (in any relative order).

  31. How to use JPG/GIF files as graphicals resources of your C++ application? (Note: By default, VC IDE lets you load bitmap, cursor, and icon files, but there is no Win32 API functions to load JPG/GIF directly. Many programs written in C++, notably IE, lets you load JPG/GIF files. The question is how?)

    Details

  32. What is the difference between painting and drawing an area (or, in MFC, between OnPaint and OnDraw message handling)?

    Details

  33. In VC IDE, when creating a new class, you can create MFC Class, Generic Class, and Form Class. What is the difference between these class types?

    Details

  34. By default, MFC ActiveX ControlWizard generates <projectname>.ocx file as main output. How to change ptoject output to DLL?

    Details

    You need to do two changes. First, open project definition file (<projectname>.def) and change LIBRARY "<projectname>.OCX" to LIBRARY "<projectname>.DLL". Second, go to Project/Settings, choose Link tab and change Release/<projectname>.ocx to Release/<projectname>.dll. If you are working in debug mode make the same changes.

  35. What is preemptive multitasking?

    Details

    In practical terms, preemptive (having power to preempt) means that the system can force an application to share processor with other applications according to own system rules. Webster links "preempt" to "acquire", "seize", "replace", "prevent" e.g. "replace with something considered to be of greater value or priority".

    Preemptive multitasking received a full support in Windows NT (and was inherited by Windows 2K/XP/Vista), and was introduced to replace collaborative multitasking in Window 3.x. Formerly preemptive multitasking was known as an important new feature of Window 95 and 98. The earlier versions of Windows had some traces of preemptive multitasking, but were not truly systems with preemptive multitasking.

    The problem with collaborative multitasking was that the program author could assign as much processor resources as he wanted to own program (albeit it was rather hypothetical opportunity not recommended by Microsoft). In the result, some authors assigned too much resources to own application so that other applications could not run at all or run very slowly, or even the whole system stalled.

    In contrast, the preemptive multitasking system manages assignment of processor times assigned to applications by its own.

  36. What static (static_cast) and dynamic (dynamic_cast) casts are used for and what is the difference between them?

    Details

  37. In COM connection point mechanism, how many client/server roundtrips are made when client makes a connection?

    Details

    Short answer: 5

  38. When you implement connection point object in ATL, what binding type you'd have by default as a result?

    Details

    ATL proxy generator generates CProxy_I<sourceinterfacename> class (Connection Point Object) that calls IDispatch:Invoke with DISPID passed explicitly. Thus, default implementation of connection points in ATL means early binding.

  39. What is VTBL?

    Details

  40. At a bare minimum, what registry entries must be available for a COM object?

    Details

    For in-proc server (DLL):

    HKCR/CLSID/{clsid}/InprocServer32

    For local server (EXE):

    HKCR/CLSID/{clsid}/LocalServer32

    These entries must show a full path to local DLL or EXE.

  41. Both new keyword in C++ and class factories in COM are used to create objects. What is the special about class factory object in COM?

    Details

  42. What is automation?

    Details

    Automation is a mechanism that provides communication between programs (components) written in different programming languages. From a technical standpoint, automation implies implementing dispatch interface (IDispatch) both on a server and on a client, and reliance on server's type library.

    As mush as polimorphism in C++ relates to use of virtual keyword, automation in COM relates to IDispatch interface and type library.

  43. Why COM HKCR entries duplicated in HKLM\Software\Classes?

    Details

  44. Why COM requires to define GUID for every interface? Note that when COM framework calls CoCreateInstance(...) to create a COM object, it consults registry to figure out an object physical location passing CLSID as a parameter, but does not use interface ID (IID) in registry operations.

    Details

  45. What is wrong when you'd try to create COM object in standard C++ way: with new keyword?

    Details

  46. What is the difference between static and dynamic invocation?

    Details

  47. Can VB, scripting language client call VTBL-interface?

    Details

  48. In ODL/IDL, what is the difference between interface and dispinterface?

    Details

  49. Why, in MFC COM, automation classes ought to be derived from CCmdTarget?

    Details

    In MFC, CCmdTarget implements IUnknown interface that must base interface for any automation interface.

  50. Who don't know and what when using IUnknown interface in COM?

    Details

  51. Why QueryInterface method must be included into every COM interface?

    Details

  52. In COM, when a client make a connection to connectable object (server), client calls IConnectionPoint::Advise (using a pointer to server's connection point). As a result, a client registers itself on a server and gets "registration ID", cookie, returned by this call. What is the purpose of this cookie, and why not, instead, identify a connection using a client's pointer?

    Details

  53. In COM, what is the difference between dispinterface and dual interface?

    Details

  54. Is IDL (ODL) file absolutely necessary when developing and deploying COM components?

    Details

  55. In COM, what is the difference between incoming and outgoing interfaces?

    Details

  56. What is the difference between parent and owner window?

    Details

  57. What is the difference between child (WS_CHILD), pop-up (WS_POPUP), and overlapped (WS_OVERLAPPED) windows?

    Details

  58. Is there are any difference between C++ fundamental data types (bool, char, short, int, long, unsigned short, unsigned int, unsigned long, float, double, etc) and correspondent data types used by Win32 and MFC (BOOL, CHAR [Win32], SHORT [Win32], INT [Win32], LONG, USHORT [Win32], UINT & DWORD, ULONG [Win32], FLOAT [Win32], ..., etc)?

    Details

  59. Why in C++ the name virtual was choosen for a functions implementing polymorphism concept?

    Details

    Apart from C++, virtual means "non-existent". In C++, virtual functions might be non-existent, i.e. they can be declared, but no implementation is provided (as with abstract virtual functions). Such functions, in a sense "do not not exist" until they are overridden in a derived class, albeit they are declared. On the other hand, non-abstract virtual functions, which are the regular case, are provided with default implementation in a base class. In this case, the term "virtual" refers to the concept that exact implementaion of the virtual function will be selected at the run-time - exact reference to implementation of virtual function "do not exists" until run-time - based on implementations of the function in derived classes and the default implmementation in the base class.

  60. Why virtual keyword is used when deriving from a class?

    Details

    Virtual keyword lets avoid creating more then one instance of a base class in a scheme with multiple inheritance. If class D inherits from classes B and C, and both classes B and C inherit from A, then two instances of base class A created when D class is created. To avoid this, B and C classes must inherit virtually from A:

    class B: virtual public A {...};
    class C: virtual public A {...};

  61. What is the difference between custom draw and owner-draw?

    Details

  62. How to colorize individual rows/cells in a List Control?

    Details

  63. COM objects can be designed using nested classes and multiple inheritance: what are the advantages and disadvantages of these options?

    Details

  64. What are typical situations when use of C++ static keyword makes sense?

    Details

    In practical terms, the static keyword used in the following situations:

    1) An application needs a several instances of a class, and some variables must have values shared among all instances, i.e. a counter variable that holds the number of class instances must be declared static.

    2) A program implements Win32 function that is using callback function, which in turn should call members of a class. Win32 function callback functions are static (declared globally) and therefore cannot access other class members. One way to let callback function to do that is to use static preudo-this pointer.

    For example, an application implements Win32 timer function that calls custom UpdateData callback function every m_nUpdateInterval milliseconds:

    SetTimer( NULL, NULL, m_nUpdateInterval, (TIMERPROC)UpdateData );

    Callback function UpdateData with pre-defined prototype should be declared static in order to access static pseudo-this pointer declared in a class:

    static UINT CALLBACK UpdateData( HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime );

    When using the static keyword have in mind the following:

    • The static keyword is a C++ feature, absent in pure C.
    • If a class member function declared static, it can not use this pointer to access other class members. It can only access static members. One of the workarounds is to use custom preudo this pointer that holds this pointer in a static variable.
    • Though static variable can be a class member it should be treated quite separately. Even if a class was not instantiated with any variable, you can access a static variable declared in a class: <classname>::<varname> anywhere in a program (see sample Static Data Members).
    • Static variable declared in a class must be defined outside of a class (on file level).
    • Static variables are automatically initialized to zero.
    • Static keyword applied to class member data and functions, but not to classes.

  65. What’s the purpose of EXP-file (export file) and how it relates to LIB-file (import library)?

    Details

  66. What’s the purpose of the second parameter in BEGIN_MESSAGE_MAP macros?

    Details

  67. What’s the difference between MFC regular and extention DLLs?

    Details

    MFC regular DLL:

    • Can be shipped both for C/C++ (non-MFC) and MFC applications.
    • MFC used internally only.
    • The program structure design reminds you about regular application (EXE) design: DLL's class derived from CWinApp, you can override virtual InitInstance() and ExitInstance() functions to initialize/free resources in DLL.
    • Includes both _USRDLL and _AFXDLL preprocessor directives

    MFC extention DLL:

    • Can be used in MFC applications only.
    • Usually used when you need to derive your own class from MFC class and package it into DLL: MFC extention DLL can export MFC-based classes.
    • The DLL's body has usual (as in Win32) DllMain() function and dwReason == DLL_PROCESS_ATTACH, dwReason == DLL_PROCESS_DETACH checks for initialization and clean-up.
    • Includes only _AFXDLL preprocessor directive, and does not define the _USRDLL directive.

    Note that MFC AppWizard (dll) automates making skeletons for both DLL types.

  68. What’s the difference between static and dynamic library?

    Details

  69. What’s the difference between implicit and explicit DLL linking (loading)?

    Details

  70. What is the difference between command and notification messages?

    Details

    Command messages are designed to handle menu, toolbar, accelerator events - so-called "user interface events". Also command messages generated when something interesting occurs with base windows controls - edit, list box, static, button, check box, radio button etc - simple windows controls inherited from Windows 3.x. These controls are different from windows common controls such as List, Tree, Tab, Month Calendar, Date Time Picker and the others that were added when Windows NT came into the scene. Common controls generate notification message to their parent window. WM_COMMAND and WM_NOTIFY, as we see, serve the same purpose for base and common controls, but must be handled differently. Both messages pass valuable information in wParam/lParam, but content of these parameters is different. For WM_COMMAND messages double-word wParam pass base control ID in its low-word part of wParam. On another hand, ID of a common control take whole space of wParam. This is one the reasons why an older Win16 program designed for Windows 3.x might crash on Windows NT/2000.

  71. What is the difference between (windows) base (basic, standard) control and (windows) common controls?

    Details

  72. Why MFC AppWizard generates virtual public destructors? See, for example, view/document classes for SDI/MDI applications.

    Details

  73. By default MDI application created by MFC AppWizard launches empty child window. How to suppress it?

    Details

    Paste a line:

    cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;

    after ParseCommandLine(cmdInfo) in InitInstance() function of your application class.

  74. What is the difference between CListView and CListCtrl MFC classes? (Or between CTreeView and CTreeCtrl, CEditView and CEditCtrl, CRichEditView and CRichEditCrtl?)

    Details

  75. In MS VC++ 6.0/NET IDE, what is the difference between Rebuild All and Build <projectname> build options?

    Details

  76. How to transfer your favotite custom settings for MS VC++ 6.0/7.0 IDE such as keyboard shortcut keys, custom macros etc to another machine or reload these settings when reinstalling Visual Studio?

    Details

  77. What are the benefits of using pointers? Think as a designer of computer language faced with an option wheather to enable using such objects as pointers or not providing them for programming.

    Details

  78. Both int a[10] and int (*a)[10] declare a pointer. Former notation declares an array of 10 integers with variable name a being actualy a constant pointer to the array, latter notation declares a pointer to array of 10 integers. What is the difference between these two pointers?

    Details

  79. When functions declared in base and derived class have the same name it is said that function in derived class overrides function in the base class being called using a reference to derived class. In the same time implementation of this function in base class can be called using reference to derived class and specifing base class in the call. The same is true if function in base class prefixed with keyword virtual. Why then to use virtual functions and what is the difference between these types of overriding?

    Details

  80. What is memory leak?

    Details

    See sample and comments here.

  81. What functions C++ compiler adds to class definition if they were not declared programmatically?

    Details

    These are four functions: default constructor, default destructor, copy constructor, overloaded assignment operator.

  82. What is the difference between private and protected data members?

    Details

    Private data members are most secured class data members compared to data members with public and protected access specifiers. Normally only access functions of a class can get their values. Protected data members bear no difference to private data members except they can be accessed in derived class.

    Both private and protected data members can be accessed by member access functions of a friend class. Note that both can not be accessed directly using reference to a class. Only access functions can reach them.

  83. What types of bindings exist in COM? In particular what is the difference between early binding and late binding?

    Details

  84. What is the difference between global variable and static member variable?

    Details

    C++ static variable can be a class member and hence shares class access rules: it can be declared public, private or protected. Though standard global variables are defined on file scope, as static variables, they can not be declared private (or public, protected).

  85. How to rename name of a project in VC IDE?

    Details

    Question might sound simplistic, but you can not rename a VC++ project in a way you would rename a file or a folder. VC++ <projectname> string have multiple instances inside .dsp file and therefore multiple lines should be renamed. VC++ IDE does not provide an option to rename a project. You can do it manuallly however. Open DSP file in a text editor and rename old entries <oldprojectname> to <newprojectname> down to the lines that discribe project source file.

  86. In C/C++, what is the difference between pre/post increment operators. In particular, what's the difference between ++i and i++?

    Details

     

  87. In C++, what is the difference between static and const keywords?

    Details

     

  88. Frequently, Microsoft VC++ generated files have a body enclosed by:

    #if !defined(AFX_<filename>_H__XXXXXXXX_XXXX_XXXX_XXXXXXXXXXXX__INCLUDED_)
    #define(AFX_<filename>_H__XXXXXXXX_XXXX_XXXX_XXXXXXXXXXXX__INCLUDED_)

    <code>

    #endif

    What's the purpose of this inclusion?

    Details

    This is to avoid accidental inclusion of a file into the project more then once. IDE generates a GUID-like name for a file which prefixed with AFX_filename_H__, has unique GUID (with signature 8-4-4-4-12) in the middle and suffixed by __INCLUDED_. Once IDE-generated the name is guaranted unique and therefore this iclusion quaranties from making accidental redundunt inclusions.

  89. In C++, what's the difference between initializations:

    (1) C<classname> * m_p<variblename>;
    (2) C<classname> * m_p<variblename> = new C<classname>;

    Details

     

  90. What is interface? Explain differencies between class and interface.

    Details

     

  91. What's the difference between TCHAR and char types?

    Details

     

  92. Describe the differencies between Win32 and COM DLL.

    Details

     

  93. In ATL, what is the purpose of ATL_NO_VTABLE macro in ATL class definition?

    class ATL_NO_VTABLE C<classname>: <listofbaseclassesandinterfaces>
    {
    <...>
    };

    Details

     

  94. What's the difference between 2 definitions:

    #define MAX_NUMBER 100

    and

    const char[] szMaxNumber = "100";

    Details

     

  95. What's the difference between 2 types of syntax when making includes:

    #include <filename.h> and #include "filename.h"?

    Details

     

  96. In Win32, what's the difference between LPSTR, LPCSTR, LPTSTR and LPTCSTR data types?:

    Details

     

  97. In C++, what's the difference between "struct" and "class" keywords?:

    Details

    By default, member access in struct is public, but in class is private. Or, another words, default access to class members is limited, while default access to struct members is not.

  98. In Win32, what's the difference between SendMessage and PostMessage?:

    Details

    SendMessage does not return immediately, it waits until a thread would process a message. Only when message is processed SendMessage returns, and calling thread resumes its work.

    PostMessage, unlike SendMessage, returns immediately, it does not care if processed or not.

  99. What's the difference between _beginthreadex and CreateThread?:

    Details

     

  100. What 3 methods are always on top of any COM interface?

    Details

    These methods are 3 methods of IUnknown interface:

    (1) QueryInterface;
    (2) AddRef;
    (3) Release;

    The pointers to these methods are on top of VTable. Any custom methods located beneath 3 methods of IUnknown interface.

  101. When writing a remote server you have a choice:

    (1) to write DCOM server;
    (2) to write TCP/IP server;

    What's the difference?

    Details

     

  102. What would be your development plan to write a language like ASP or PHP?:

    Details

     

© 2002-2007, Marcel Lambert (lambert1791 at gmail dot com)

Contact me if you have an interesting project
(software projects, IT consulting & writings, business startups),
ongoing or that you plan to realize, by
lambert1791 at gmail dot com.