very good site for com & dcom questions
http://www.equestionanswers.com/com-dcom-questions.php
http://www.equestionanswers.com/com-dcom/what-is-ole.php
http://www.equestionanswers.com/com-dcom/what-is-com.php
http://www.equestionanswers.com/com-dcom/advantages-com.php
http://www.equestionanswers.com/com-dcom-questions.php
http://www.equestionanswers.com/com-dcom/what-is-ole.php
http://www.equestionanswers.com/com-dcom/what-is-com.php
http://www.equestionanswers.com/com-dcom/advantages-com.php
Question Bank
On
Win 32
Microsoft Foundation Classes (MFC)
Component Object Model (COM)
Contents
Version History
Version No.
|
Date
|
Prepared / Modified by
|
Modifications / Reviewed By
|
1.0
|
17-09-2008
|
Brijendra Trivedi
| |
1. Win32
1.1 Windows Fundamentals and Architecture
What is the difference between method and message?
Re: What is the difference between method and message?
| ||||||
Message:
Objects communicate by sending messages to each other. A
message is sent to invoke a method.
Method:
Provides response to a message. It is an implementation of
an operation.
|
0
|
Smita
| ||||
Re: What is the difference between method and message?
| ||||||
Method is a function or procedure that is defined for a
class and typically can access the internal state of an
object of that class to perform some operation. While
message is refer to instruction that is send to object which
will invoke the related method.
|
Whats the difference bet. WM_Close & WM_Quit?
if you want to clear exit your App - post WM_CLOSE to its main window; :)
it you want some problem py exiting (including memory leaks, and so on) you may try to use WM_QUIT
it you want some problem py exiting (including memory leaks, and so on) you may try to use WM_QUIT
The WM_QUIT message indicates a request to terminate an application and is generated when the application calls the PostQuitMessage function. The WM_CLOSE message is sent as a signal that a window or an application should terminate. An application can prompt the user for confirmation, prior to destroying a window, by processing the WM_CLOSE message and calling the DestroyWindow function only if the user confirms the choice.
How much type of messages are their in Windows?
What is difference between SendMessage() and PostMessage() function?
The PostMessage function places (posts) a message in the message queue associated with the thread that created the specified window and then returns without waiting for the thread to process the message. On the other hand, SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message. Both are called with same set of parameters.
What is difference between GetMessage() and PeekMessage() function?
GetMessage function waits for a message to be placed in the queue before returning where as PeekMessage function does not wait for a message to be placed in the queue before returning.
What is message pump in Win32 programming?
What is the Message Queue
Lets say you were busy handling the
WM_PAINT
message and suddenly the user types a bunch of stuff on the keyboard. What should happen? Should you be interrupted in your drawing to handle the keys or should the keys just be discarded? Wrong! Obviously neither of these options is reasonable, so we have the message queue, when messages are posted they are added to the message queue and when you handle them they are removed. This ensure that you aren't going to miss messages, if you are handling one, the others will be queued up untill you get to them.
What is a Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
- The message loop calls
GetMessage()
, which looks in your message queue. If the message queue is empty your program basically stops and waits for one (it Blocks). - When an event occures causing a message to be added to the queue (for example the system registers a mouse click)
GetMessages()
returns a positive value indicating there is a message to be processed, and that it has filled in the members of theMSG
structure we passed it. It returns0
if it hitsWM_QUIT
, and a negative value if an error occured. - We take the message (in the
Msg
variable) and pass it toTranslateMessage()
, this does a bit of additional processing, translating virtual key messages into character messages. This step is actually optional, but certain things won't work if it's not there. - Once that's done we pass the message to
DispatchMessage()
. WhatDispatchMessage()
does is take the message, checks which window it is for and then looks up the Window Procedure for the window. It then calls that procedure, sending as parameters the handle of the window, the message, andwParam
andlParam
. - In your window procedure you check the message and it's parameters, and do whatever you want with them! If you aren't handling the specific message, you almost always call
DefWindowProc()
which will perform the default actions for you (which often means it does nothing). - Once you have finished processing the message, your windows procedure returns,
DispatchMessage()
returns, and we go back to the beginning of the loop.
What is processing unit in Win32 programming?
Explain how message communication happen in Win32 application.
Which API is used to hide window?
ShowWindow(hWnd,SW_HIDE);
Which API is used to disable/enable window?
What is the function to repaint a window immediately?
What Message displayed when a window is destroyed?
What message we use to limit the size of window?
How a window application terminate?
How to create a window in Win32 application?
How to register a window in Win32 application?
How to display a window in Win32 application?
Can we define our own message in Win32 application?
What is subclassing?
What is a handle?
2. Microsoft Foundation Classes (MFC)
See Document
2.1 Fundamentals
What is the difference between MFC and Win32?
Win32 is a set of Windows APIs written in C and MFC is a
framework built arround Win32. All MFC functions internally
use Win32 APIs. And MFC is written in C++. |
What are the features of ‘CObject’ class?
CObject is the principal base class for the Microsoft
Foundation Class Library. It serves as the root not only for
library classes such as CFile and CObList, but also for the
classes that you write. CObject provides basic services,
including
CObject provide three important feature :
Serialization Support
Runtime class Information Support
Diagnostic and debugging support
What is the use of CCmdTarget?
CCmdTraget has the implementation of the Message map.
Message map routes the commands & messages to the member
functions you write to handle them. Key frame work classes
derived from the CCmdtarget includes CWnd, Cview etc..
If you need new user class handel the messages, derive the
class from any of the class which are derived from
CCmdTarget.
How do you identify RTTI in VC++?
Re: how do u identify RTTI in vc++
| ||||||
Check if class is derived directly or indirectly from
CObject. CObject provides facility of RTTI.
With this functionality enable IsKindof like functions can
be used and utilised any where for that object.
|
0
|
Amol Vaidya
| ||||
Re: how do u identify RTTI in vc++
| ||||||
In VC++ compiler project properties->C/C++ ->language-
>Enable Runtime Information to YES (/GR) compiler option
|
0
|
Raghavender
| ||||
Re: how do u identify RTTI in vc++
| ||||||
Check if class is derived directly or indirectly from
CObject. CObject provides facility of RTTI check to its
derived classes.
 DECLARE_DYNAMIC and IMPLEMENT_DYNAMIC, permit run-
time access to the class name and its position in the
hierarchy. This, in turn, allows meaningful diagnostic
dumping.
 CObject::IsKindOf function to determine the class
of your objects at run time.
|
What are LPCTSTR, LPTSTR, LPSTR and LPCSTR?
What is difference between SendMessage() and PostMessage() function?
Answer:
The difference between these two API calls is the way that they return control to the calling application. With SendMessage control is not returned to the calling application until the window that the message was sent to has completed processing the sent message, however with PostMessage control is returned to the calling application immediately, regardless of weather or not the sent message has been processes.
postMessage: Sends a message in the message queue associated with the thread and returns without waiting for the thread to process that messaage.
SendMessage: calls the window procedure for the specified window and does not return until the window procedure has processed the message.
SendMessage: calls the window procedure for the specified window and does not return until the window procedure has processed the message.
PostMessage is a Asynchronous function where as SendMessage is a synchronous function.
Read more: http://wiki.answers.com/Q/What_is_the_difference_between_PostMessage_and_SendMessage#ixzz1SyVXrs00
What is difference between GetMessage() and PeekMessage() function?
What is the difference between GetMessage and PeekMessage ?
GetMessage function waits for a message to be placed in the queue before returning where as PeekMessage function does not wait for a message to be placed in the queue before returning.
How we can find out Memory leaks? In what way it can be avoided?
What the difference is between ASSERT and VERIFY?
The main difference between ASSERT and VERIFY is when you compile the release build of the program.
ASSERT will not be present in the release build version of the executables/dlls, and its expression that would have been evaluated will be deleted.
VERIFY will be present in the release build version of the executables/dlls but its expression that would have been evaluated will be left intact.
ASSERT will not be present in the release build version of the executables/dlls, and its expression that would have been evaluated will be deleted.
VERIFY will be present in the release build version of the executables/dlls but its expression that would have been evaluated will be left intact.
Since Windows is a message-oriented operating system, a large portion of programming for the Windows environment involves message handling. Each time an event such as a keystroke or mouse click occurs, a message is sent to the application, which must then handle the event.
The Microsoft Foundation Class Library offers a programming model optimized for message-based programming. In this model, "message maps" are used to designate which functions will handle various messages for a particular class. Message maps contain one or more macros that specify which messages will be handled by which functions. For example, a message map containing an ON_COMMAND macro might look something like this:
BEGIN_MESSAGE_MAP( CMyDoc, CDocument )
ON_COMMAND( ID_MYCMD, OnMyCommand )
// ... More entries to handle additional commands
END_MESSAGE_MAP( )
The ON_COMMAND macro is used to handle command messages generated by menus, buttons, and accelerator keys. Macros are available to map the following:
What is the use of CObject::Dump function?
How to convert a CString variable to char* or LPTSTR?
How to handle command line arguments from simple MFC application?
Using GetCommandLineArgs() function you can get the
arguments in MFC application at any time. In InitInstance
() function you can change the behaviour of the
application using those values.
m_lpCmdLine Corresponds to the lpCmdLine parameter passed by Windows to WinMain. Points to a null-terminated string that specifies the command line for the application. Use m_lpCmdLine to access any command-line arguments the user entered when the application was started. m_lpCmdLine is a public variable of type LPTSTR.
Code ex.
BOOL CMyApp::InitInstance()
{
// …
{
// …
if (m_lpCmdLine[0] == _T(”))
{
// Create a new (empty) document.
OnFileNew();
}
else
{
// Open a file passed as the first command line parameter.
OpenDocumentFile(m_lpCmdLine);
}
{
// Create a new (empty) document.
OnFileNew();
}
else
{
// Open a file passed as the first command line parameter.
OpenDocumentFile(m_lpCmdLine);
}
// …
}
}
2.2 MFC Architecture
Which MFC function is used to display output?
MFC has device context class CClientDC. It has OnDraw()
function. A statement in OnDraw functionsuch as
CClientDC dc;
dc.TextOut(0, 0, "Hellow");
sends text to the display.
What is the initial function to be called in MFC and what it will do?
What function is used to disable a control at runtime?
Give some names of classes which are not derived from CObject class?
many classes are not derived from CObject.
like
CArchive
CRunTimeClass
CString
Cpoint
CRect
CTime,CTimeSpan
CDataExchange
CSingleLock
CMultiLock
CCmdUI and many more...
What is the use of DDV and DDX routines?
DDX(DoDataExchange()
Is use To associate Control variable To Control ID.
DDV(DoDataValidation)
Is used to Set the range of control Value.
The MFC framework provides an efficient mechanism for transferring and validating data in a dialog box through the DDX and DDV routines. Dialog Data Exchange (DDX) is an easy way to initialize the controls in a dialog box and gather data input by the user. Dialog Data Validation (DDV) is an easy way to validate data entry in a dialog box.
The framework calls CWnd::DoDataExchange to exchange and validate dialog data. When a class is derived from CDialog, you need to override this member function if you wish to utilize the framework's automatic data exchange and validation
What are the design patterns of an MFC application?
Why not virtual functions to handle messages?
What is purpose of InitInstance() function in MFC?
2.3 Messages Handling
What is the use of message map?
What is command routing in VC++?
What if we provide two message handlers for same message?
2.4 Graphics
What are GDI Objects?
What is device context? What is its purpose?
Difference between CClientDC,CPaintDC and CWindowDC?
Explain StretchBlt and BitBlt
How to load Bitmap at dialog background in an MFC application?
How to repaint a client area in MFC?
What OnCtlColor() handler do?
2.5 Menus, Toolbars, Status Bars and other controls
How to handle dynamic menus in MFC?
How many types of combo box are their?
How can you change button shape at run time?
How can we change the color of a drop down combobox elements?
What are property pages? What are they used for?
2.6 Creating and Using Dialog Boxes
How many types of dialog box are their and their differences?
How to initialize contents of a dialog?
What is the use of OninitDialog?
What is the use of Update Data function?
What is difference between Modal and Modeless dialog box? Give example.
How to destroy a modal and modeless dialog box?
Which are the common dialogs in MFC and what is each used for?
What is subclassing?
Subclassing Defined
Subclassing is a technique that allows an application to intercept messages destined for another window. An application can augment, monitor, or modify the default behavior of a window by intercepting messages meant for another window. Subclassing is an effective way to change or extend the behavior of a window without redeveloping the window. Subclassing the default control window classes (button controls, edit controls, list controls, combo box controls, static controls, and scroll bar controls) is a convenient way to obtain the functionality of the control and to modify its behavior. For example, if a multiline edit control is included in a dialog box and the user presses the ENTER key, the dialog box closes. By subclassing the edit control, an application can have the edit control insert a carriage return and line feed into the text without exiting the dialog box. An edit control does not have to be developed specifically for the needs of the application.
What is message reflection?
2.7 Document/View Architecture
What is the difference between the SDI and MDI?
Can you explain Doc/View architecture in MFC?
How to access document object from view?
How CView class update any change in other CView class?
What are the advantages of using Doc/View or SDI over DialogBox?
What is the command routing in SDI/MDI application?
To Established the relationship between CView and CDocument
with Cdoctemplate and CMultidoctemplate.Cdoctemplate for
SDI and CMultidoctemplate for MDI
What are some differences between a form view and a dialog box?
What is CSingleDocTemplate?
CSingleDocTemplete defines a document template for SDI
applications. A document templet defines the relationship
between three types of classes, those are document, view
and frame window.
CSingleDocTemplete object can be create only one at a time.
So SDI application allows to open only one document at a
time.
Just call CSingleDocTemplete constructor remaining will be
handeled by the framework internally.
Can you explain the relationship between document, frame and view?
2.8 Persistence
What is serialization? Which function is responsible for serializing data?
serialization is a process by which the object writes a record of itself to a persistent storage medium.
Serialization is used for object persitence. using this you
can store your object current state in disk. The same state
you can get after restarting your application.
A serializable class usually has a Serialize member
function, and it usually uses the DECLARE_SERIAL and
IMPLEMENT_SERIAL macros, as described under class CObject.
serialization means writing data to the file and reading
data from the file.
This is supported by CArchive class and the function is
serialize()
serialize function is like
if(ar.IsStoring())
{
//code for storing data
}
else(ar.IsLoading())
{
//Code for loading data
}
What are CArchive class and its role?
What is role of SetModifiedFlag?
2.9 Synchronization Objects
What is thread & process?
Threads are similar to processes, but differ in the way that they share resources. Threads are distinguished from processes in that processes are typically independent, carry considerable state information and have separate address spaces. Threads typically share the memory belonging to their parent process.
What are synchronization objects?
What is difference between Mutex and Critical Section?
What is Multithreading?
What types of threads are supported by MFC framework?
2 types of thread in MFc are UserInterface thread and worker thread. UserInterface threads maintain the message loops and used to handles user input,creates windows and process messges sent to those windows.Worker thread don't use message loops and mainly used to perform background operations such as printing etc.,Created using AfxBeginThread bypassing ThreadFunction to create worker thread and Runtime class object to create a user interface thread.
Given two processes, how can they share memory?
What is a critical section and how is it implemented?
Mutex as the name suggest allows a mutullay exclusive access to a shared resource among the threads. Critical section is a piece of code that can be executed safely to be accessed by two or more threads. Criticalsection provides synchronization means for one process only, while mutexes allow data synchronization across processes. Means two or more threads can share the common resources among more than one application or process boundaries in mutex.
What is a Mutex and how is it implemented?
An object of class CMutex represents a “mutex” — a synchronization object that allows one thread mutually exclusive access to a resource. Mutexes are useful when only one thread at a time can be allowed to modify data or some other controlled resource. For example, adding nodes to a linked list is a process that should only be allowed by one thread at a time. By using a CMutex object to control the linked list, only one thread at a time can gain access to the list.
To use a CMutex object, construct the CMutex object when it is needed. Specify the name of the mutex you wish to wait on, and that your application should initially own it. You can then access the mutex when the constructor returns. Call CSyncObject::Unlock when you are done accessing the controlled resource.
An alternative method for using CMutex objects is to add a variable of type CMutex as a data member to the class you wish to control. During construction of the controlled object, call the constructor of the CMutex data member specifying if the mutex is initially owned, the name of the mutex (if it will be used across process boundaries), and desired security attributes.
To access resources controlled by CMutex objects in this manner, first create a variable of either type CSingleLock or type CMultiLock in your resource’s access member function. Then call the lock object’s Lock member function (for example, CSingleLock::Lock). At this point, your thread will either gain access to the resource, wait for the resource to be released and gain access, or wait for the resource to be released and time out, failing to gain access to the resource. In any case, your resource has been accessed in a thread-safe manner. To release the resource, use the lock object’s Unlock member function (for example, CSingleLock::Unlock), or allow the lock object to fall out of scope
To use a CMutex object, construct the CMutex object when it is needed. Specify the name of the mutex you wish to wait on, and that your application should initially own it. You can then access the mutex when the constructor returns. Call CSyncObject::Unlock when you are done accessing the controlled resource.
An alternative method for using CMutex objects is to add a variable of type CMutex as a data member to the class you wish to control. During construction of the controlled object, call the constructor of the CMutex data member specifying if the mutex is initially owned, the name of the mutex (if it will be used across process boundaries), and desired security attributes.
To access resources controlled by CMutex objects in this manner, first create a variable of either type CSingleLock or type CMultiLock in your resource’s access member function. Then call the lock object’s Lock member function (for example, CSingleLock::Lock). At this point, your thread will either gain access to the resource, wait for the resource to be released and gain access, or wait for the resource to be released and time out, failing to gain access to the resource. In any case, your resource has been accessed in a thread-safe manner. To release the resource, use the lock object’s Unlock member function (for example, CSingleLock::Unlock), or allow the lock object to fall out of scope
How to setup a timer?
What are different ways of thread synchronization?
How can we create thread in MFC framework?
2.10 Dynamic-Link Libraries
What are DLL’s and which are different type of DLL’s?
What is LoadLibrary() function?
What is GetProcAddress() Function?
Differences between Static library and Dynamic library
Differences between Static linking and dynamic linking?
Differences between implicit linking and explicit linking?
What is the difference between Extension DLL and Regular DLL?
3. COM / DCOM / ATL/Active-X
3.1 Component Object Modal (COM)
Differentiate normal DLL to COM DLL
Define and explain COM?
How would you create an instance of the object in COM?
What is IUnknown? What methods are provided by IUnknown?
What should QueryInterface functions do if requested object was not found?
What are the purposes of AddRef, Release and QueryInterface functions?
How we implement the ActiveX controls in VC++application
What is OLE? How do you handle drag and drop in OLE?
What is an ActiveX interface?
What are the two types of events generated by ActiveX controls?
What is a moniker?
What happens when client calls CoCreateInstance?
What is the difference, if any, between OLE and COM?
C is aggregated by B, which in turn aggregated by A. Our client requested C. What will happen?
What are the different compatibility types when we create a COM component?
Which namespace do the classes, allowing you to support COM functionality, are located?
Explain object pooling?
3.2 Distributed Component Object Modal (DCOM)
Which tool is used to configure the port range and protocols for DCOM communications?
What kind of components can be used as DCOM servers?
How does a DCOM component know where to instantiate itself?
Explain queued components.
How do you make a NET component talk to a COM component?
Explain JIT activation?
3.3 Active Template Library (ATL)
What Is the ATL Control-Hosting API?
Which ATL Classes Facilitate ActiveX Control Containment?
How to implement multiple dual interfaces?
How to reuse interface implementation in source in ATL projects?
How to implement static object hierarchies in ATL?
How to obtain data from the client via an outgoing event dispinterface in ATL?
Will ATL create all of the topological relationships within the topology layer?
What are the known problems with the ATL 2.0 Object Wizard?
What problems might be encountered when using _ATL_MIN_CRT? What causes the linker error that _main is unresolved during Release builds?
What are the reasons an ATL server might fail to register?
3.4 Active X
What is ActiveX control?
What is an ActiveX interface?
What are the two types of events generated by ActiveX controls?
What are the properties exposed by ActiveX controls?
What Is an OLE Custom Control?
What interface must be supported by an ActiveX control?
What four types of properties are supported by an ActiveX control?
What MFC base classes provide support for ActiveX controls?
4. Mislaneous
what is proces ?
|
how to create SDK based ATL ? how to create SDK based COM?
|
How to Load Controls Specified at Run Time?
|
What Is "AtlAxWin80"?
|
What Is the ATL Control-Hosting API?
|
Which ATL Classes Facilitate ActiveX Control Containment?
|
How to Implement multiple dual interfaces ?
|
How to Reuse interface implementation in source in ATL projects ?
|
How to Implement static object hierarchies in ATL ?
|
How to Use structs in Automation-compatible interfaces?
|
How to Obtain data from the client via an outgoing event dispinterface in ATL ?
|
Will ATL create all of the topological relationships within the topology layer?
|
Does ATL require an application server to operate?
|
What are the known problems with the ATL 2.0 Object Wizard?
|
What problems might be encountered when using _ATL_MIN_CRT? What causes the linker error that _main is unresolved during Release builds?
|
5. My Own Choice:
Stack Vs Heap
ü The stack is the memory set aside as scratch space for a thread of execution. When a function is called, a block is reserved on the top of the stack for local variables and some bookkeeping data. When that function returns, the block becomes unused and can be used the next time a function is called. The stack is always reserved in a LIFO order; the most recently reserved block is always the next block to be freed. This makes it really simple to keep track of the stack; freeing a block from the stack is nothing more than adjusting one pointer.
ü The heap is memory set aside for dynamic allocation. Unlike the stack, there's no enforced pattern to the allocation and deallocation of blocks from the heap; you can allocate a block at any time and free it at any time. This makes it much more complex to keep track of which parts of the heap are allocated or free at any given time; there are many custom heap allocators available to tune heap performance for different usage patterns.
6. References:
Book
|
What it covers
|
Scot Wingo and George Shephard's MFC Internals (Addison Wesley)
|
MFC implementation details.
|
Mike Blaszczak's The Revolutionary Guide to Win32 Programming Using Visual C++ (WROX Press)
|
MFC usage and other Visual C++ product information.
|
Jeff Prosise's Programming Windows 95 with MFC (Microsoft Press)
|
For Win32 SDK Windows programmers and C++ programmers new to MFC.
|
Adam Denning's ActiveX Controls Inside Out, Second Edition (Microsoft Press)
|
Develop MFC-based ActiveX controls using COM technology.
|
Frank Crockett's MFC Developer's Workshop (Microsoft Press)
|
Solutions for commonly-encountered coding problems: interface elements, ActiveX controls, databases, and more.
|
David J. Kruglinski's Inside Visual C++ (Microsoft Press)
|
MFC fundamentals.
|
Mastering MFC Development (Microsoft Press)
|
A compact disc (CD) that trains you to use MFC and the Visual C++ development system.
|