MFC interview questions

Discussion in 'MFC' started by coderzone, Apr 14, 2006.

  1. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    39
    Trophy Points:
    28
    Subject says it all.

    1. What is the base class for MFC Framework ?
    2. If i derive a new class from CObject what are the basic features my derived wil get ?
    3. What is the use of CCmdTarget ?
    4. What is document-view architecture ? Give me one real time example for SDI ?
    5. Can you explaing the relashionship between document,frame and view ?
    6. How to access document object from view ?
    5. What is the entry point for window based applications ?
    6. Explain the flow for a simple win32 based application ?
    7. How to handle command line arguements from simple MFC application ?
    8. What is model and modeless dialog box ? Give some examples?
    9. How to create open & save dialogs ?
    10.What is CSingleDocTemplate?
    11.What is the difference between hinsrtance and hprevinstance in WinMain function?
    12.Explaing about MDI and CMultiDocTemplate ?
    13.Tell me the different controls in MFC ?
    14. What is the use of OninitDialog ?
    15. What is the use of UpdateData funciton ?
    16.What is the difference between GetMessage and PeekMessage ?
    17.How to update all the views whenver document got updated ?
    18.How to handle RTTI in MFC ?
    19.What is serialization ?which function is responsible for serializing data ?
    20.What is CArchive class dowes?
    21.What is thread & process?
    22.Explain about different kinds of threads in MFC?
    23.Tell me about different kinds of synchranization objects ?
    24.what is the use of Mutex and critical section ?
    25.What is socket?
    26.What is the difference between Synchronous sockets and asynchronous sockets?
    27.Have you ever used win32 APIs ?
    28.What is the difference between ANSI Code and UNICODE ?
    29.What is the difference between regular dlls and extended dlls?
    30.what is the use of AFX_MANAGE_STATE ?
    31. What’s the difference between PostMessage and SendMessage?
    32. Describe the Document/View architecture.
    33. What’s the difference between Modal and Modeless Dialog?
    34. How to create a Modeless Dialog?
    35. How to setup a timer?
    36. Name the Synchronization objects.
    37. What is a critical section and how is it implemented?
    38. What is CMutex?
    39. Given two processes, how can they share memory?
    38. What is a message map, and what is the advantage of a message map over virtual functions?
    40. What is the difference between ASSERT and VERIFY?
    41. Why wizards generate enum IDD for dialogs? [Added by Shabbir]

    I will be answering them slowly to each of them. If anyone else interested can do the same. It will be a very good resource thread for the beginer.
     
    Last edited: Apr 14, 2006
  2. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    39
    Trophy Points:
    28
    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.
     
  3. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    39
    Trophy Points:
    28
    What’s 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 then returns without waiting for the thread to process the message.

    The 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.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    How to create a Modeless Dialog?

    [comment]Coderzone thanks for letting me know about this thread. I have made it sticky and I hope other members will definitely have some replies coming.[/comment]
    m_pModeless is a variable of type CDialog or any of its descendants.

    m_pModeless->Create(IDD_DIALOG1, this);
    m_pModeless->ShowWindow(SW_SHOW);

    this pointer as a paramter suggest we are creating a child dialog of the current dialog/window.
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    How to setup a timer?

    Use the SetTimer function
    Code:
    UINT_PTR SetTimer(          HWND hWnd,
        UINT_PTR nIDEvent,
        UINT uElapse,
        TIMERPROC lpTimerFunc
    );
    To kill the timer use
    Code:
    BOOL KillTimer(int nIDEvent);
    Where the nIDEvent is the ID returned by the SetTimer Function.
     
  6. anantwakode

    anantwakode New Member

    Joined:
    Apr 4, 2006
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer..
    Location:
    Pune (India)
    Name the Synchronization objects ?

    Following are the synchronization objects
    1) Critical Section
    2) Event
    3) Mutex
    4) Semaphore

    Classes provided for above synchronization objects are:

    1) CCriticalSection
    2) CEvent
    3) CMutex
    4) CSemaphore
     
  7. anantwakode

    anantwakode New Member

    Joined:
    Apr 4, 2006
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer..
    Location:
    Pune (India)
    What Is CMutex ?

    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

    from MSDN
     
  8. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    39
    Trophy Points:
    28
    What is the difference 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.
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    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.
     
  10. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    what is the use of AFX_MANAGE_STATE ?

    By default, MFC uses the resource handle of the main application to load the resource template. If you have an exported function in a DLL, such as one that launches a dialog box in the DLL, this template is actually stored in the DLL module. You need to switch the module state for the correct handle to be used. You can do this by adding the following code to the beginning of the function:
    AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
    This swaps the current module state with the state returned from AfxGetStaticModuleState until the end of the current scope.

    If all your resources lies in the single DLL you can even change the default handle to the DLL handle with the help of AfxSetResourceHandle function.
     
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Why wizards generate enum IDD for dialogs?

    It's good programming practice to do it this way, as from the client code you can always refer to the CMyDlg::IDD without worrying what the actual constant is.
     
  12. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    What is CArchive class does?

    As a quote from MSDN.
     
  13. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    39
    Trophy Points:
    28
    How to handle command line arguements from simple MFC application ?

    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.

    Example
    Code:
    BOOL CMyApp::InitInstance()
    {
       // ...
      
       if (m_lpCmdLine[0] == _T('\0'))
       {
          // Create a new (empty) document.
          OnFileNew();
       }
       else
       {
          // Open a file passed as the first command line parameter.
          OpenDocumentFile(m_lpCmdLine);
       }
      
       // ...
    }
     
  14. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is the base class for MFC Framework ?

    CObject
     
  15. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    If I derive a new class from CObject what are the basic features my derived will get?

    Searialization, Debugging support, Runtime time class information, compatibility with collection classes.
     
  16. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    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
     
    Last edited by a moderator: Oct 30, 2006
  17. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is document-view architecture ? Give me one real time example for SDI ?

    Document/view architecture, which defines a program structure that relies on document objects to hold an application's data and on view objects to render views of that data. MFC provides the infrastructure for documents and views in the classes CDocument and CView.

    example of SDI is a wordpad application
     
    Last edited by a moderator: Oct 30, 2006
  18. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    Can you explain the relashionship between document,frame and view ?

    The frame window is the application's top-level window. It's normally a WS_OVERLAPPEDWINDOW-style window with a resizing border, a title bar, a system menu, and minimize, maximize, and close buttons.
    The view is a child window sized to fit the frame window so that it becomes the frame window's client area.
    The application's data is stored in the document object, a visible representation of which appears in the view.
    For an SDI application, the frame window class is derived from CFrameWnd, the document class is derived from CDocument, and the view class is derived from CView or a related class such as CScrollView.
     
  19. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    How to access document object from view ?

    Using GetDocument() function within a CView class.
     
  20. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is the entry point for window based applications ?

    WinMain() is the entry point for window based applications.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice