Common Windows Interview QuestionsSend your Question/Answer General Questions
You don't have to mention all differences. Some of them are:
Memory Management
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.
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
You may mention the following advantages:
Extension, Regular and pure Win32 DLL (without MFC)
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
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.)
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!!!):
Multithreading
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.
Critical section provides synchronization means for one process only, while
mutexes allow data synchronization across processes.
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.
Using AfxBeginThread.
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
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.
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
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
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().
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
CView => CDocument => CFrameWnd => CWinApp
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.
CMultiDocTemplate.
AddDocTemplate.
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.
CMap, CList
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.
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.
ODBC
ODBC stands for Open Database Connectivity - a standard protocol for accessing
relational databases based around SQL.
DSN is a data source name. DSN stores information about how to connect to a
particular ODBC database.
User, System, File DSN.
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.
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.
DTC log, application log or trace statement, depending on where is the problem
occured.
Use function AVG of SQL.
Misc.
You could think of several way to debug this:
There are four differences between debug and release builds:
Guys, please let me know the winner list.
You may mention IsExist() method of Win32 or FindFirst/FindNext combination.
|