Tuesday, March 3, 2009

Part - 4 MFC Interview Questions & Answers

Q:- What is socket?
Ans:- A "socket" is an endpoint of communication: an object through which your application communicates with other Windows Sockets applications across a network.The two MFC Windows Sockets programming models are supported by the following classes: CAsyncSocket and CSocket

Q:- What is the difference between Synchronous sockets and asynchronous sockets?
Ans:- Consider a server application that is listening on a specific port to get data from clients. In synchronous receiving, while the server is waiting to receive data from a client, if the stream is empty the main thread will block until the request for data is satisfied. Hence, the server cannot do anything else until it receives data from the client. If another client attempts to connect to the server at that time, the server cannot process that request because it is blocked on the first client. This behavior is not acceptable for a real-world application where we need to support multiple clients at the same time. 

In asynchronous communication, while the server is listening or receiving data from a client, it can still process connection requests from other clients as well as receive data from those clients. When a server is receiving asynchronously, a separate thread (at the OS level) listens on the socket and will invoke a callback function when a socket event occurs. This callback function in turn will respond and process that socket event.

Q:- Have you ever used win32 APIs ?
Ans:- MFC is a wrapper around win32 API, It provides classes which uses the win32 API, Some of the API's we usually work with are : GetDlgItemInt,GetDlgItemText,GetWindowTextA,Messag eBoxA,CreateFile,CreateMutex,CreateEvent,WaitForSi ngleObject,CreateWindow,ShowWindow etc.,

Q:- What is the difference between ANSI Code and UNICODE ?
Ans:- ANSI code represents 8bytes data where UNICODE represents 16bytes data for supporting universal languages. One major draw back to ASCII was you could only have 256 different characters. However, languages such as Japanese and Arabic have thousands of characters. Thus ASCII would not work in these situations. The result was Unicode which allowed for up to 65,536 different character

Q:- What is the difference between regular dlls and extended dlls?
Ans:- Regular dlls wraps only the c/c++ functions. Where extention dlls include c++ interfaces where we can create the objects of it and use in our classes. Extended dlls support object oriented concepts.Regural dlls uses mfc internally and exported functions can be used by any mfc or non-mfc applications.Extention dlls implements reusable classes derived from mfc library,built using dll version of mfc.Only mfc executables(applications/dll-shared version of mfc) can use extention dlls.extention dlls used for passing mfc derived objects b/w applications and dlls. Regulardlls linked both statically and dynamically but extended dlls links dynamically.

Q:- What is a message map, and what is the advantage of a message map over virtual function ?
Ans:- MessageMap is a logical table that maps the windows messages to the member functions of the class. We use message maps over virtual function because of lots of overhead. If every windows message had a virtual function associated with it , there would be several hundred bytes per window class of vtable. Message maps means we only pay for the messages we use.

Q:- Given two processes, how can they share memory?
Ans:- Processes and thread are very similar but they differ in the way they share their resources. Processes are independent and have its own address space. If two independent processes want to communicate they do this by using the following techniques 1.Message Passing 2.Sockets 3. named pipes
Or
Use memory-mapped files to share data memory between processes

Q:- How to restrict only one instance of a class object to be created?
Ans:- Create a Named Mutex.
HANDLE hMutex=CreateMutex(TRUE,_T(“NamedMutex”))
And check the Mutex existence for each of your instance launch and dont allow it to launch if it exists.

Q:- How do I dynamically change the mainframe menu?
Ans:- CMenu newMenu;
newMenu.LoadMenu (IDR_MENU1);
AfxGetMainWnd()->SetMenu( &newMenu );
AfxGetMainWnd()->DrawMenuBar();
newMenu.Detach ();

0 comments:

Post a Comment

© All Content is Under Copyright Protection © 2008-2009 VC++ Interview Tips | Site Best Viewed in Firefox