(Interview) Microsoft Technologies Interview Questions ( VC++)

Microsoft Technologies Interview Questions

[VC++ Interview Questions]


What is OLE ? How do you handle drag and drop in OLE ?

Object Linking and Embedding (OLE) clipboard is a more capable clipboard than the windows traditional clipboard. To transfer a large image using a legacy clipboard one must allocate enough memory space to copy this image. However using the OLE clipboard you can transfer the bitmap in a more sensible medium like a file on a hard disk.

OLE drag and drop is a visual method of transferring data. Unlike having separate commands like cut, copy and paste the OLE drag and drop lets you grab a piece of data with the mouse and drop it in the desired location.

So to summarize it there are two broad differences between OLE and legacy clipboard. OLE clipboard is completely COM based and secondly it supports storage medium other than global memory.

OLE drag and drop is programmatically very similar to OLE clipboard. The data provider or data source creates a data object that encapsulates the data and makes an IDataObject pointer available. The data consumer or drop target retrieves the IDataObject and uses it to extract data from the data object. The drop source initiates a drag and drop operation by passing an IDataObject pointer to ::DoDragDrop. Any window that is interested inbeing a drop target registers itself with the system by calling ::RegisterDragDrop. If drop occurs in a registered window then the drop target is handed the IDataObject pointer passed to ::DoDragDrop.

Can you explain IUnknown interface used in COM ?

COM is an acronym for Component Object Model. COM is a way of building objects that is independent of any programming language.  Every COM object implements an interface named IUnknown. It contains three methods: -         QueryInterface: Returns a pointer to another interface -         AddRef:  Increments the objects reference count -         Release: Decrements the objects reference count. One of the rules of COM says that given a pointer to an interface a client can call any IUnknown method through that pointer as well as any methods that are specific to that interface. Hence all interfaces must support the three IUnknown methods in addition to their own methods.

Can you explain message routing and message loop ?

When a window is visible on the screen it undergoes various stages such as CreateWindow, ShowWindow, etc. Once the window is displayed on the screen it must now make itself ready to take keyboard and mouse input from the user. Windows maintains a message queue for each windows program currently running under windows. When an input occurs, the OS translates this event into a message that it places into the windows message queue. A program receives messages from the message queue by executing a block of code known as the message loop.  While (GetMessage(&msg, NULL, 0, 0)){            TranslateMessage(&msg);            DispatchMessage(&msg);}  The GetMessage call passes to windows a pointer to the message and these fields of the message are filled by windows.  The TranslateMessage call passes the msg structure back to windows for some keyboard translation. The DispatchMessage call passes the message to windows which sends the message to appropriate windows procedure for processing the message. So this means that windows call the window procedure

Which are the various message map macros ?

Message maps are an MFC approach to windows programming. Instead of writing a WinMain () function that sends messages to your WindProc and then writing a WindProc that checks which kind of message this is and then calls another of your functions, you just write the function that will handle the message, and you add a message map to your class that says, in effect, "I will handle this sort of message." The framework handles whatever routing is required to send that message to you.A number of macros are used in message maps:- DECLARE_MESSAGE_MAP: used in the include file to declare that there will be a message map in the source file.- BEGIN MESSAGE MAP: marks the beginning of the message map in the source file.- END MESSAGE MAP: marks the end of the message map- ON_COMMAND: used to delegate the handling of a command to a function of a class.- ON_COMMAD_RANGS: used to handle a group of commands- ON_MESSAGE: used to delegate the handling of a user defined message to a function- ON_NOTIFY: used to handle the control notification message with some extra information and calls a member function of a class.

Explain command routing ?

A command is a special type of message. Windows generates a command whenever user chooses a menu item, clicks a button or tells the system to do something. Windows send a WM_COMMAND message for menu choices, button clicks or WM_NOTIFY for list box selection. Commands and notifications are passed around by the operating system just like any other message until they get into the top of OnWndMsg() and MFC command routing starts.

Command messages have the first parameter, the resource id of the menu item that was chosen or the button that was clicked.

Command routing is a mechanism used by OnWndMsg to send commands to objects that can?t receive messages. Only objects of type CWnd can receive messages but all objects that inherit from CCmdTarget including CWnd and CDocument can receive commands and notifications.

How do commands and notifications get to the class though? The answer is by command routing. OnWndMsg calls CWnd::OnCommand() or CWnd::OnNotify() which in turn call OnCmdMsg() which is a virtual function, which means that different command targets have different implementations. The implementation of a frame window sends the commands to its views and documents. This is how commands get handled by m

What do you mean by ?Managed Code? ?

Managed code is code written for .Net runtime or CLR (Common Language Runtime). The code that provides enough information to allow the common language runtime to perform the following tasks: -         Given an address inside the code locate the metadata describing the method. -         Walk the stack -         Handle exceptions -         Store and retrieve security information Related to managed code is managed data. Managed data is data that is allocated but freed automatically by the garbage collection process. With garbage collection when an item goes out of scope the runtime cleans it up.