Sie sind auf Seite 1von 12

4/2/2014 VC++ Interview Questions | C++ and VC++ Tips

http://vcpptips.wordpress.com/vc-interview-questions/ 1/12
C++ and VC++ Tips
A tip can save your precious time..
VC++ Interview Questions
Starting point of windows application?
WinMain() is the entry point of Windows applications.
Parameters of WinMain()
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE
hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
hInstance The handle of the currently running module.
hPrevInstance A handle to a previous instance of the application. For a
Win32-based application, this parameter is always NULL.
lpCmdLine Points to a null-terminated string specifying the command
line for the application.
nCmdShow Specifies how the main window of a GUI application would
be shown.
What is windows programming? How its working?
Windows is an event driven programming mechanism, in which
applications respond to events by processing messages sent by the
operating system. An event could be a keystroke, a mouse click, or a
command for a window to repaint itself, among other things. The entry
point for a Windows program is a function named WinMain, but most of
the action takes place in a function known as the window procedure. The
window procedure processes messages sent to the window. WinMain
creates that window and then enters a message loop, alternately retrieving
messages and dispatching them to the window procedure. Messages wait in
a message queue until they are retrieved.
Startup of a Simple Windows Program?
LONG WINAPI WndProc (HWND, UINT, WPARAM, LPARAM);
4/2/2014 VC++ Interview Questions | C++ and VC++ Tips
http://vcpptips.wordpress.com/vc-interview-questions/ 2/12
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE
hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
MSG msg;
//Fill WNDCLASS structure
RegisterClass (&wc);
hwnd = CreateWindow();
ShowWindow (hwnd, nCmdShow);
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
WPARAM wParam,
LPARAM lParam)
{
}
What is MFC?
MFC is the C++ class library Microsoft provides to place an object-oriented
wrapper around the Windows API. MFC is also an application framework.
More than merely a collection of classes, MFC helps define the structure of
an application and handles many routine chores on the applications behalf.
Starting with CWinApp, the class that represents the application itself,
MFC encapsulates virtually every aspect of a programs operation. The
framework supplies the WinMain function, and WinMain in turn calls the
application objects member functions to make the program go. One of the
CWinApp member functions called by WinMainRunprovides the
message loop that pumps messages to the applications window. The
framework also provides abstractions that go above and beyond what the
Windows API has to offer.
What is an application framework?
The application framework is a collection of classes and the structure of an
4/2/2014 VC++ Interview Questions | C++ and VC++ Tips
http://vcpptips.wordpress.com/vc-interview-questions/ 3/12
The application framework is a collection of classes and the structure of an
application which handles many routine chores on the applications behalf.
The framework also provides abstractions that go above and beyond what
the Windows API has to offer.
MFC is an application framework it acts as object oriented wrapper
around the Windows API.
Principle base class in MFC?
CObject is the principal base class for the Microsoft Foundation Class
Library. The majority of MFC classes are derived, either directly or
indirectly, from CObject.
CObject provides basic services, including
- Serialization support
- Run-time class information
- Object diagnostic output
- Compatibility with collection classes
Difference between ASSERT and VERIFY?
ASSERT evaluates the expression only in the debug version and will throw
an exception if the result is 0 and the program termintes.
VERIFY evalutes the expression in Debug and Release version also and if
the result is 0, will throw an exception only in Debug mode.
What is the difference between PostMessage and SendMessage?
The PostMessage function places (posts) a message in the message queue
associated with the thread that created the specified window and returns
without waiting for the thread to process the message.
The SendMessage function sends the specified message to a window or
windows. It calls the window procedure for the specified window and does
not return until the window procedure has processed the message.
What is the difference between PeekMessage and GetMessage?
You can use the PeekMessage function to examine a message queue during
a lengthy operation. PeekMessage is similar to the GetMessage function,
both check a message queue for a message that matches the filter criteria
and then copy the message to an MSG structure. The main difference
between the two functions is that GetMessage does not return until a
message matching the filter criteria is placed in the queue, whereas
PeekMessage returns immediately regardless of whether a message is in the
queue.
4/2/2014 VC++ Interview Questions | C++ and VC++ Tips
http://vcpptips.wordpress.com/vc-interview-questions/ 4/12
What is the difference between hInstance and hWnd?
hWnd is the windows handle and is how the OS defines a window when
talking about it inside the PC.
hInstance is the OSs handle for the program when running it.
What is the difference between Modal and Modeless Dialog?
Modal dialog box captures the message loop, whereas model less does not.
Call DoModal to create the dialog window and its controls for a modal
dialog. If you wish to create a modeless dialog, call Create in the constructor
of your Cdialog class.
Example for Model Dialog is Save, Save As Dialog in MS -Word.
Example for Modeless Dialog is Find,Replace dialogs.
What is the use of CCmdTarget?
It is the base class for the MFC library message map architecture. Which
maps commands/messages to the member functions to handle them.
Classes derived from this are CWnd,CWinApp,CFrameWnd,CView,
CDocument
What is the difference between hinsrtance and hprevinstance in
WinMain function?
hInstance : will be having the handle of the current instance
hPrevInctance : will be having the handle of last instance, hPrevInstance is
NULL if only one instance is running
Describe the Document/View architecture.
In MFC 1.0, an application had two principal components: an application
object representing the application itself and a window object representing
the applications window. The application objects primary duty was to
create a window, and the window in turn processed messages.
MFC 2.0 changed the way Windows applications are written by
introducing the document/view architecture. In a document/view
application, the applications data is represented by a document object and
views of that data are represented by view objects. Documents and views
work together to process the users input and draw textual and graphical
representations of the resulting data. MFCs CDocument class is the base
class for document objects, and CView is the base class for view objects. The
applications main window, whose behavior is modeled in MFCs
CFrameWnd and CMDIFrameWnd classes, is no longer the focal point for
message processing but serves primarily as a container for views, toolbars,
status bars, and other user interface objects.
4/2/2014 VC++ Interview Questions | C++ and VC++ Tips
http://vcpptips.wordpress.com/vc-interview-questions/ 5/12
MFC supports two types of document/view applications. Single document
interface (SDI) applications support just one open document at a time.
Multiple document interface (MDI) applications permit two or more
documents to be open concurrently and also support multiple views of a
given document
What is document?
In a document/view application, data is stored in a document object. The
document object is created when the framework instantiates a class derived
from CDocument. It is an abstract representation of a programs data that
draws a clear boundary between how the data is stored and how it is
presented to the user. That means the sole purpose of a document object is
to manage an applications data.
What is view?
View objects exist for two purposes: to render visual representations of a
document on the screen and to translate the users inputparticularly
mouse and keyboard messagesinto commands that operate on the
documents data. Thus, documents and views are tightly interrelated, and
information flows between them in both directions.
Distinguish between Windows OnPaint and Views OnDraw
overridable functions?
Windows OnPaint function executes corresponding to each WM_PAINT
messages. But in the case of document-view architecture when a view
receives a WM_PAINT message, it invokes views OnDraw function.
Actually the framework fields the WM_PAINT message, creates a
CPaintDC object, and calls the views OnDraw function with a pointer to
the CPaintDC object.
The fact that the view doesnt have to construct its own device context
object is a minor convenience. The real reason the framework uses OnDraw
is so that the same code can be used for output to a window, for printing,
and for print previewing. When a WM_PAINT message arrives, the
framework passes the view a pointer to a screen device context so that
output will go to the window. When a document is printed, the framework
calls the same OnDraw function and passes it a pointer to a printer device
context.
What is command routing?
One of the most remarkable features of the document/view architecture is
that an application can handle command messages almost anywhere.
Command messages is MFCs term for the WM_COMMAND messages
that are generated when items are selected from menus, keyboard
4/2/2014 VC++ Interview Questions | C++ and VC++ Tips
http://vcpptips.wordpress.com/vc-interview-questions/ 6/12
accelerators are pressed, and toolbar buttons are clicked. The frame window
is the physical recipient of most command messages, but command
messages can be handled in the view class, the document class, or even the
application class by simply including entries for the messages you want to
handle in the classs message map. The flow of command messages from
Active View to DefWindowProc is know as command routine.
ActiveView -> Active Views Doc -> Document Template -> Frame Window
-> Application Object -> DefWindowProc
How Message Map works in an MFC application?
The message map functionality in an MFC application works by the
support of 3 Macros, DECLARE_MESSAGE_MAP,
BEGIN_MESSAGE_MAP, and END_MESSAGE_MAP and the
WindowProc function implementation.
MFCs DECLARE_MESSAGE_MAP macro adds three members to the
class declaration: a private array of AFX_MSGMAP_ENTRY structures
named _messageEntries that contains information correlating messages
and message handlers; a static AFX_MSGMAP structure named
messageMap that contains a pointer to the classs _messageEntries array
and a pointer to the base classs messageMap structure; and a virtual
function named GetMessageMap that returns messageMaps address.
BEGIN_MESSAGE_MAP contains the implementation for the
GetMessageMap function and code to initialize the messageMap structure.
The macros that appear between BEGIN_MESSAGE_MAP and
END_MESSAGE_MAP fill in the _messageEntries array, and
END_MESSAGE_MAP marks the end of the array with a NULL entry.
Thus corresponding to each message a class can traverse through its and
base classes message map entries to find a handler till it to reach the
DefWindowProc.
What is the difference between thread and process?
In the Microsoft Win32 environment, every running application constitutes
a process and every process contains one or more threads of execution. A
thread is a path of execution through a programs code, plus a set of
resources (stack, register state, and so on) assigned by the operating system.
50 responses
24 01 2013
4/2/2014 VC++ Interview Questions | C++ and VC++ Tips
http://vcpptips.wordpress.com/vc-interview-questions/ 7/12
anamika (11:44:23) :
this doc is very helpful
thank u
Reply
Sanoop S P (05:27:19) :
Thank you Anamika
Reply
AK (11:05:44) :
welcome
Reply
santhoshkumar (16:58:52) :
useful one..
Reply
Sanoop S P (03:42:30) :
Thank you Santhosh
Reply
Rana Pratap (08:00:42) :
Thank u so much
Reply
Sanoop S P (05:25:29) :
Thanks for reading
Reply
Kalyan (17:56:03) :
Useful information
Reply
Sanoop S P (02:34:17) :
Thank you
Reply
Arun (02:32:21) :
26 01 2013
3 10 2013
11 03 2013
12 03 2013
15 03 2013
20 03 2013
20 03 2013
24 03 2013
31 03 2013
4/2/2014 VC++ Interview Questions | C++ and VC++ Tips
http://vcpptips.wordpress.com/vc-interview-questions/ 8/12
thank you
Reply
Sanoop S P (05:38:50) :
Welcome
Reply
vara prasad (00:17:37) :
It really saved my precious time.Thank you brother.
Reply
Sanoop S P (12:09:24) :
Thank you.
Reply
Dixika (18:24:37) :
thank you so much for providing such really helpful notes
Reply
Sitar (14:04:14) :
Really very nice
Reply
Sanoop S P (12:47:02) :
Thank you!
Reply
santhosh (20:27:03) :
nice one to read again
Reply
Sanoop S P (06:06:38) :
Thank you Santhosh
Reply
fharook (23:01:49) :
Thanks dudes, its really help full to all
31 03 2013
1 04 2013
1 04 2013
4 04 2013
11 04 2013
16 04 2013
26 04 2013
28 04 2013
30 04 2013
4/2/2014 VC++ Interview Questions | C++ and VC++ Tips
http://vcpptips.wordpress.com/vc-interview-questions/ 9/12
Reply
puli malyadri (04:32:38) :
i learned a lot
regards,
tiger.
Reply
shajee (00:46:57) :
Very usefull. Please add more questions
Reply
Sanoop S P (06:51:29) :
Thank you Shajee
Reply
panchu (10:39:16) :
hello .good article
Reply
Sanoop S P (07:14:22) :
Thank you
Reply
Mahesh (11:43:43) :
Nice article, it would be good if you do write Version 2
Reply
Sanoop S P (16:49:34) :
Thank you Mahesh
Reply
vinalGtm (17:59:25) :
Gud Web siteReally HelpfullKeep it Up
Reply
Sanoop S P (06:20:50) :
Thank you.
2 05 2013
12 05 2013
12 05 2013
18 05 2013
19 05 2013
3 06 2013
7 06 2013
23 06 2013
24 06 2013
4/2/2014 VC++ Interview Questions | C++ and VC++ Tips
http://vcpptips.wordpress.com/vc-interview-questions/ 10/12
Reply
Prashanth (07:09:08) :
Good amount of knowledge gained, if you have some more please share
it,
Reply
Sanoop S P (15:52:13) :
Thank you Prashanth
Reply
Prashanth (09:34:49) :
Do you have any links or materials for more questions.
Reply
sriman (02:13:11) :
Thanks for the information
Reply
laxman (04:32:37) :
thank you, you saved my day!
Reply
Ashwin (08:29:47) :
Very good information. Thank you so much
Reply
Jram Ch (08:50:38) :
thanku dude this is very help full information
Reply
Satyanarayana (16:07:33) :
thank you
Reply
Vellaidurai (18:10:02) :
Very good article. Many thanks Sanoop
Reply
1 07 2013
1 07 2013
3 07 2013
19 09 2013
18 10 2013
12 11 2013
16 11 2013
21 11 2013
3 12 2013
4/2/2014 VC++ Interview Questions | C++ and VC++ Tips
http://vcpptips.wordpress.com/vc-interview-questions/ 11/12
Sanoop S P (06:39:33) :
Thank you Vellaidurai.
Reply
laxman (05:50:09) :
nice information..
same questions are being asked by the interviewers
Reply
Ramesh (13:43:00) :
Good work thanks for sharing
Reply
Sunil JG (01:46:43) :
Good one friend, Thanks for your effort
Reply
Arvind (11:15:56) :
very good collection of qns and ans.
Thank you
Reply
fharook (10:41:46) :
There no more other question are there laxman, any way we have to
thanks to Sanoop.. thanks alot
Reply
shine (10:33:14) :
Here is some more MFC and C++ Questions .
http://www.programminggallery.com/article/vc__/general_programming/general_faqs_and_consupts/some_common_mfc_faq_s_and_tips
Reply
vijay (19:24:53) :
IS very helpful
Thank you sir
Reply
6 12 2013
9 12 2013
17 12 2013
30 12 2013
31 12 2013
23 01 2014
29 01 2014
10 02 2014
4 03 2014
4/2/2014 VC++ Interview Questions | C++ and VC++ Tips
http://vcpptips.wordpress.com/vc-interview-questions/ 12/12
Sanoop S P (13:20:15) :
Thank you Vijay
Reply
Ramanathan (13:19:52) :
Fantastic Explainations for windows programming using Visual C++
Reply
Sanoop S P (13:19:48) :
Thank you.
Reply
anji (13:06:50) :
Thanks for giving this good information.Anji
Reply
Sanoop S P (16:32:18) :
Thanks Anji
Reply
Blog at WordPress.com. The Freshy Theme.
Follow
Follow C++ and VC++ Tips
Powered by WordPress.com
27 02 2014
4 03 2014
11 03 2014
11 03 2014

Das könnte Ihnen auch gefallen