Home
Up

Common Windows Interview Questions

Send your Question/Answer

General Questions

  1. Tell the differences between Windows 95 and Windows NT?
  2. You don't have to mention all differences. Some of them are:
    1. Lack of Unicode implementation for most of the functions of Win95.
    2. Different extended error codes.
    3. Different number window and menu handles.
    4. Windows 95 implements some window management features in 16 bits.
    5. Windows 95 uses 16-bit world coordinate system and the coordinates restricted to 32K.
    6. Deletion of drawing objects is different.
    7. Windows 95 does not implement print monitor DLLs of Windows NT.
    8. Differences in registry.
    9. Windows 95 does not support multiprocessor computers.
    10. NT implementation of scheduler is quite different.
    11. Different driver models.
    12. Win95 was built with back-compatibility in mind and ill-behaving 16-bit process may easily corrupt the system.
    13. Win95 starts from real DOS, while WinNT uses DOS emulation when one needs a DOS.
    14. Win95's FAT is built over 16-bit win3.1 FAT (not FAT32!) (actually, Win95's FAT contains two FATs)

Memory Management

  1. What is the effective way of DIB files management?
  2. Memory-mapped file is the best choice for device-independent bitmaps. MMF allows to map the file to RAM/SWAP addresses and to let Windows handle all load/unload operations for the file.
  3. What should you be aware of if you design a program that runs days/weeks/months/years?
  4. When your program should run for a long time, you should be careful about heap allocations, because if you use new/delete intensively in your application, the memory becomes highly fragmented with a time. It is better to allocate all necessary memory in this case that many times small blocks.

DLL

  1. What are the advantages of using DLL's?
  2. You may mention the following advantages:
    1. DLLs are run-time modular. DLL is loaded when the program needs it.
    2. Used as a code sharing between executables.
  3. What are the different types of DLL's?
  4. Extension, Regular and pure Win32 DLL (without MFC)
  5. What are the differences between a User DLL and an MFC Extension DLL?
  6. Extension DLL supports a C++ interface, i.e. can export whole C++ classes and the client may construct objects from them. Extension DLL dynamically links to MFC DLLs (those which name starts with MFC??.DLL) and to be synchronous with the version it was developed for. Extension DLL is usually small (simple extension DLL might be around 10K) Regular DLL can be loaded by any Win32 environment (e.g. VB 5) Big restriction is that regular DLL may export only C-style functions. Regular DLLs are generally larger. When you build a regular DLL, you may choose a static link (in this case MFC library code is copied to your DLL) and dynamic (in this case you would need MFC DLLs to be presented on the target machine)

Multiple Inheritance

  1. What do you have to do when you inherit from two CObject-based classes?
  2. First of all, this is a bad idea regardless of what the interviewer tells you. Secondly, if you forced to use condemned diamond structure, read the Technical Note 16 in MSDN, which discusses why MFC does not support multiple inheritance and what to do in case you still need it (there are a few problems with CObject class, such as incorrect information, returned by IsKindOf() of CObject for MI, etc.)
  3. What are the additional requirements for inheritance from CWnd-based classes?
  4. Again, this is a bad idea. Try to find alternative solution. Anyway, if you have to multiply inherit from CWnd-based class, the following are additional requirements to the above conditions (again, this is extremely bad question for interview!!!):
    • There must be only one CWnd-derived base class.
    • The CWnd-derived base class must be the first (or left-most) base class.

Multithreading

  1. What is a "mutex"?
  2. Mutexes are the mechanism of process synchronization that might be used to synchronize data across multiple processes. Mutex is a waitable object while a critical section is not. Mutexes are significantly slower than critical sections.
  3. What's the difference between a "mutex" and a "critical section"?
  4. Critical section provides synchronization means for one process only, while mutexes allow data synchronization across processes.
  5. What might be wrong with the following pseudo-code:
    INT I=2
    FUNCTION F
    BEGIN
    DO
       I = I + 1
       IF I = 4 THEN BREAK
    END DO
    END
    
    This code is not thread safe. Suppose one thread increments I to 3 and then returns to the beginning of DO statement. Then it increments I to 4 and now context switch happens. Second thread increments I to 5. From this moment the code shown will execute forever until some external force intervention. Solution is obviously using some synchronization object to protect I from being changed by more than one thread.
  6. What is a deadlock ?
  7. A deadlock, very simply, is a condition in which two or more threads wait for each other to release a shared resource before resuming their execution. Because all threads participating in a deadlock are suspended and cannot, therefore, release the resources they own, no thread can continue, and the entire application (or, worse, more than one application if the resources are shared between threads in multiple applications) appears to hang.
  8. How can we create thread in MFC framework?
  9. Using AfxBeginThread.
  10. What types of threads are supported by MFC framework?
  11. Working thread and windows thread. Working thread usually does not have a user interface and easier to use. Windows thread has an user interface and usually used to improve responsiveness of the user input.

Message Map

  1. When ON_UPDATE_COMMAND_UI is called? (message may vary)
  2. When a user of your application pulls down a menu, each menu item needs to know whether it should be displayed as enabled or disabled. The target of a menu command provides this information by implementing an ON_UPDATE_COMMAND_UI handler.
  3. What is a "hook"?
  4. A point in the Windows message-handling mechanism where an application can install a subroutine to monitor messages. You need hooks to implement your own Windows message filter.

Exception Handling

  1. (another stupid one) What are the difference between MFC Exception macros and C++ exception keywords?
  2. Stupid question. There are few differences such as names, different last throw and so on. Probably, the major difference is that MFC macros have born when C++ did not have exception handling and based on C exception mechanism (actually, MFC macros may accept exception of only CException class or class, derived from CException, where as C++ exception mechanism accepts exception of ANY type)

Reusable Control Class

  1. How would you set the background of an edit control to a customized color?
  2. You have several choices, but the simplest one is subclassing. Kruglinski in his "Inside Visual C++" describes pretty well this process. Generally, you derive the class from known control class, override the messages you want (like WM_CTLCOLOR) and then in init function like OnInitialUpdate of CDialog, subclass the control with SubclassDlgItem().
  3. What is Message Reflection? How could you accomplish the above task using message reflection?
  4. See Technical Note 62 of MSDN. Usually, message is handled in the parent class that means you have to override message handler for each parent. Sometimes it is nice to handle a message in the control itself, without parent invocation. Such handling mechanism is called message reflection. Control "reflects" message to itself and then processes it. Use ON_<MESSAGE_NAME>_REFLECT macro to create a reflected message.

MFC

  1. What is the command routing in MFC framework?
  2. CView => CDocument => CFrameWnd => CWinApp
  3. What's the purpose of CView class? CDocument class? What are relationships between them?
  4. The CView class provides the basic functionality for user-defined view classes. A view is attached to a document and acts as an intermediary between the document and the user: the view renders an image of the document on the screen or printer and interprets user input as operations upon the document. The CDocument class provides the basic functionality for user-defined document classes. A document represents the unit of data that the user typically opens with the File Open command and saves with the File Save command. Users interact with a document through the CView object(s) associated with it. A view is a child of a frame window. The relationship between a view class, a frame window class, and a document class is established by a CDocTemplate object. A view can be attached to only one document, but a document can have multiple views attached to it at once.
  5. What class is responsible for document template in MDI application?
  6. CMultiDocTemplate.
  7. What function must be used to add document template?
  8. AddDocTemplate.
  9. What the main objects are created for SDI and MDI applications?
  10. CWinApp - application object. For MDI application with New document implementation CDocTemplate, CDocument, CView, CMainFrame. If your application is SDI, your CMainFrame class is derived from class CFrameWnd. If your application is MDI, CMainFrame is derived from class CMDIFrameWnd. For MDI application CMDIChildWindow is also created.
  11. Name 2 MFC collection classes
  12. CMap, CList
  13. Name 10 MFC classes. Specify their hierarchy.
  14. No words (I mean no civilized words) When you see questions like this you may become suspicious about company which gave such question. Anyway, it's easy to put hierarchy chart in your bag and you may mention 4 classes that created upon new application in MFC and CObject (at least, you already have 5) Then, you may mentioned collection and OLE classes if you remember.
  15. What's wrong with the following code:
    CObArray *pArray = new CObArray;
    for(int i = 0; i < 10; i++)
    {
       CMyObj *pObj  = new CMyObj;
       pArray->Add(pObj);
    }
    for(int j = 0; j < pArray->GetSize(); j++)
    {
       CMyObj *pObj = pArray->GetAt(j);
       delete pObj;
       pArray->RemoveAt(j);
    }
    
  16. This is classical example of double delete. pArray->RemoveAt(j) will delete an element which is already deleted. You may also shine saying that RemoveAt accepts the second parameter which is number of elements to remove.
  17. How would you implement a method

ODBC

  1. What is ODBC?
  2. ODBC stands for Open Database Connectivity - a standard protocol for accessing relational databases based around SQL.
  3. What is DSN?
  4. DSN is a data source name. DSN stores information about how to connect to a particular ODBC database.
  5. What are 3 objects that can be used to connect to a database?
  6. User, System, File DSN.
  7. What is a [declarative] referential integrity? What are the disadvantages of it?
  8. FOREIGN KEY constraints defined as part of a table definition that enforce proper relationships between tables. The constraints ensure that proper actions are taken when DELETE, INSERT, and UPDATE statements remove, add, or modify primary or foreign key values. The DRI actions enforced by FOREIGN KEY constraints can be supplemented with additional referential integrity logic defined in triggers on a table.
  9. What is an outer join?
  10. A join that includes all the rows from the joined tables that have met the search conditions, even rows from one table for which there is no matching row in the other join table. For result set rows returned when a row in one table is not matched by a row from the other table, a value of NULL is supplied for all result set columns that are resolved to the table that had the missing row.
  11. How to debug ODBC problem?
  12. DTC log, application log or trace statement, depending on where is the problem occured.
  13. You have a table, consisting of employeeId, FirstName, LastName, Department and Wage. Write a SQL statement to calculate the average salary per department.
  14. Use function AVG of SQL.

Misc.

  1. Application fails. We have a loop for 800,000. It fails on 756,322. How can we get an information before it fails.
  2. You could think of several way to debug this:
    • Set the condition in debugger to stop when loop is passed around 756321 times.
    • Throw an exception within a loop (may be not the best idea since exception does not show you the exact location of the fail.
    • Create a log file and to put detailed information within a loop.
  3. Our Debug version works fine, but Release fails. What might be a reason and what should be done?
  4. There are four differences between debug and release builds:
    1. heap layout (you may have heap overwrite in release mode - this will cause 90% of all problems),
    2. compilation (check conditional compilation statements, assertion functions etc.),
    3. pointer support (no padding in release mode which may increase chances of a pointer to point into sky) and
    4. optimization. Check the project settings.
    The following may help you to isolate the problem:
    1. You may turn off the optimization. Optimizers are buggy by themselves;
    2. You may try to include the debug information in the release build and use tools like BugTrapper to analyze the code execution sequence;
    3. You may add logging capabilities to your code to attempt to catch misbehaving module/spot of your program. Note: TRACE macros won't help you in Release builds!
    4. Finally, when all other methods fails, you may try to analyze your code in debug build at the assembly level, but this may be considered only as the last resort!
  5. Specify top 10 Win32 functions and structures
  6. Guys, please let me know the winner list.
  7. Name 2 C++ ways in Windows to determine that the file MyFile.txt exists in a directory C:\MyDir
  8. You may mention IsExist() method of Win32 or FindFirst/FindNext combination.