Вы находитесь на странице: 1из 5

What is CMutex? How can we use it? CMutex is a synchronization class which uses synchronization object named as mutex.

It allows multiple program thread can share the same resource by taking turns. At the starting of the program it creates a mutex at beginning and then a system gives a unique ID or name for it. After that, any thread which needs the resource can use the mutex to lock the resource. For example access of a file. To use CMutex construct its object when it is needed to be accessed. Give the name of mutex and to the application will own it. You can access mutex when constructor returns again to the start. When you are done accessing the controlled resource then call CSyncObject::Unlock. b.) What are frames and CFrameWnd? Frames contain view windows. Frame windows allow the user the capability to use status bars, toolbars, and splitters. CFrameWnd contains the implementation to perform the function of a main window as wells as it keeps track of currently active view that is independent of Windows active window or input focus. It also provides the functionality of a Windows single document interface (SDI) overlapped. This is contained in CFrameWnd class. For example: class CFrameWnd : public CWnd What is CWinThread class? Explain its advantages At the beginning of every application has one and only one thread, called as primary thread. CWinApp which is the user derived class encapsulates this thread. In this case pointer to your CWinApp object is also a pointer to the CWinThread object for the primary thread. Once your application gets going, it can create as many new threads as it wants to manage various tasks. CWinApp is derived from CWinThread. It also allows multiple threads within given application. CWinThread supports two types of threads: Worker threads- it has no message pump i.e. thread that performs background calculations User interface threads- it has message pump i.e. messages received from system. It can be declared as: class CWinThread : public CCmdTarget The advantages which it has is: It can assign more than one thread at a time like a multi-threading system. It terminates the application without any hassles. What is function regex and regex_search function? Regex- Defines a template class to parse regular Expressions, and several template classes and functions to search text for matches to a regular expression object. It is represented as: Explain modal and modeless dialog box? What is the difference between modal and modeless dialog box? Modal dialog box is the dialog box in which user response is required before continuing with the program. The Paragraph dialog box of WordPad is a good example of it when it is displaying, the user cannot use any other part of WordPad unless he or she closes this object first Modeless dialog box is the dialog box in which the screen remain stable and available to all the user for use at any time but it doesnt stop their and allow other user work to be carried out without any interference. For example The Find dialog box of WordPad.

The difference between Modal and modeless dialog box are:Modal captures the message loop and doesnt move on to other objects until the current object is closed but modeless doesnt capture it. Modal doesnt allow its parents window to be accessed until all other windows are closed but it is allowed in modeless. Example of Modal is Save and Save As in Microsoft word until they are opened you can not do anything until you close the window whereas Find and Replace can simultaneously be executed together. Difference between critical section, mutex and semaphore. A critical section in which the process may be changing common variables, updating table, writing a file and perform another function. The important problem is that if one process is executing in its critical section, no other process is to be allowed to execute in its critical section. Each process much request permission to enter its critical section. A semaphore is a tool for synchronization and it is used to remove the critical section problem which is that no two processes can run simultaneously together so to remove this two signal operations are used named as wait and signal which is used to remove the mutual exclusion of the critical section. as an unsigned one of the most important synchronization primitives, because you can build many other Decrementing the semaphore is called acquiring or locking it, incrementing is called releasing or unlocking. A mutex is a special case of the semaphore and also known as binary mutex it can have only two values minimum of 0 and maximum of 1, meaning it can be either locked or unlocked. It is used to prevent more than one thread from accessing the same data while allowing multiple threads to run on it. What is OLE? How do you handle drag and drop in OLE? OLE is meant for Object Linking and Embedding. It is a way of handling compound documents (Single document which can store data in multiple formatssuch as text, graphics, video, and sound). It is an object oriented paradigm. It incorporates many services of OOP- encapsulation, polymorphism, and an object-based architecture. Drag-and-drop feature of OLE is primarily same as copy and paste feature through which data can be transferred from one place to another. When you use the Clipboard to copy or paste data, a number of steps are required. OLE drag and drop is much more general. It allows user to drag and drop any data that could also be placed on the Clipboard. The processes are reduced in this as you select the source window (drop source), drag it to the desired destination (drop target) and drop it by releasing the mouse. It eliminates the needs of menus and only requires the source and target must be open at the time of drag and drop.

What are the differences between MFC Exception macros and C++ exception keywords? MFC Exception macro automatically deletes a caught exception when the object goes out of the scope whereas the code using C++ exception keywords does not, as user has to explicitly mention the function to delete and catch the exception. MFC exception macros automatically see the out of scope objects and solve the problem whereas in C++

exception keyword we have to mention a function which contains the code to catch the out of scope objects. What is the use of message map? Advantages of a message map. Any system is a message driven system. Every event has to be noted down and stored somewhere like a mouse click or a printer signal sends a message to the running application which in turn handles the message. The Microsoft Foundation Class (MFC) Library supports a message driven programming mode in which the central component is the Message Map which is used to map the message to the right process or device and allows the user to perform without any interference. It is also a very flexible and well integrated with tools such as MFC AppWizard and ClassWizard. As message maps are created from a set of macros then it allows the flexibility and functionality to be maintained and allow user to work efficiently. It has advantages of flexibility, you can store command messages, control notifications and register the messages which are going to be used later on. What is the use of AFX_MANAGE_STATE? AFX_MANAGE_STATE structure contains global data for the module, that is, the portion of the module state that is pushed or popped and also it is used to protect the exported function in DLL. Its syntax is like this AFX_MANAGE_STATE(AFX_MODULE_STATE* pModuleState ) where pModuleState is the pointer to the AFX_MANAGE_STATE structure. It is enable for static MFC libraries as well as MFC DLLs. Differentiate between a template class and class template Template Class is also termed as function templates which are special functions that can operate with generic types. It allows creating a function template whose functionality can be taken to more than one type or class without repeating entire code for each type. The declarations are:template <class identifier> function_declaration; template <typename identifier> function_declaration; Class template have the members that use template parameters. It specifies how individual classes can be constructed much like the way a class specifies and how individual objects can be constructed. Through this plain classes can be derived whereas through template class plain templates can be derived. For example:template <class T> What is the base class for MFC Framework? What are the main features provided by CObject class? CObject class is the main base class for MFC Framework. It is the mother of all other classes. Almost all classes in MFC are derived from CObject one of the exception is CString. It provides several important features such as Serialization - conversion of object to a series of bytes that can be written to disk and brought back later to restore your object to its previous state. 1) Runtime type information 2) Debugging features 3) Object diagnostic output 4) Compatibility with collection classes What is CALLBACK? How it work? What is the advantage of CALLBACK? Explain with an example.

Callback is a function that is called from a function pointer. If you pass a pointer as an argument to another function and another function calls back the previous function it is called as CALLBACK. The main advantage of this is to detach caller from the callee. In this caller doesnt care about the callee but caller knows that there is some callee exists with some prototype and with some functionality in hand. So it provides and abstraction. For example, if suppose you write a library program that provides implementation of all sorting algorithms. But you dont want to put any sorting logic into your functions by yourself and making it more general to use. You want client to make decision of the algorithm they want to use. So, for this the function pointers will be used which will be making callbacks. Pragma #pragma directive is an instruction to the compiler and is ignored during the preprocessing and it is also used to control the actions of the compiler in a particular portion of a translation unit without affecting the translation unit as a whole. It is included in the beginning for example like this #pragma COPYRIGHT "string" How to handle dynamic menus in MFC? MFC got built in function to handle dynamic menus. It comes after the message maps. By overriding OnCmdMsg() you can catch the menu events so you can handle them properly. In your OnCmdMsg() handler, there are two cases to handle: When the user selects an item. When the data has to be updated (enabled/disabled, checked/unchecked). Then menus can be handled by certain classes and header files such as :Cmenu, Createmenu, Insrtmenu and Appendmenu functions. What happens when client calls CoCreateInstance? When client calls the CoCreateInstance() function it actually used to create a single instance of the appropriate object. The function looks like: STDAPI CoCreateInstance( REFCLSID rclsid, /*Class identifier (CLSID) of the object */ LPUNKNOWN pUnkOuter, /*Pointer to whether object is or isnt part of an aggregate */ DWORD dwClsContext, /*Context for creating the object*/ REFIID riid, /*Reference to the identifier of the interface (a pointer in C, a reference variable in C++*/ LPVOID * ppv /*Indirect pointer to requested interface if successful, NULL otherwise*/) This function accepts 4 input parameters and returns an output parameter which is the interface pointer of the COM component. How to create a Modeless Dialog? For creation of Modeless Dialog doesnt require OK and Cancel buttons, because they are associated with

modal operations. User closes it by pressing the close box (a small x) in the upper-right corner of the dialog box. If you do decide to use OK and Cancel buttons, you must override the default OnOK() and OnCancel() message handlers and create your own that call DestroyWindow(). You must do this because the default functions call EndDialog(), which only closes a dialog box in modal operation. Create() function is used to create the window. void CDialogTemplDoc::OnShowdialogDisplaymodeless() { CModeless* pDlgModeless = new CModeless; pDlgModeless->Create(CModeless::IDD); } Delete() function is used to delete the instance of the created window. void CModeless::PostNcDestroy() { CDialog::PostNcDestroy(); // Delete Ourselves delete this; } ShowWindow() function is used to show the window on the screen to the user dynamically.

Вам также может понравиться