Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger


Showing posts with label COM. Show all posts
Showing posts with label COM. Show all posts

Thursday, 19 June 2008

VB 6, COM, DCOM, Microsoft platform interview questions

  1. 3 main differences between flexgrid control and dbgrid control
  2. ActiveX and Types of ActiveX Components in VB
  3. Advantage of ActiveX Dll over ActiveX Exe
  4. Advantages of disconnected recordsets
  5. Benefit of wrapping database calls into MTS transactions
  6. Benefits of using MTS
  7. Can database schema be changed with DAO, RDO or ADO?
  8. Can you create a tabletype of recordset in Jet-connected ODBC database engine?
  9. Constructors and destructors
  10. Controls which do not have events
  11. Default property of datacontrol
  12. Define the scope of Public, Private, Friend procedures?
  13. Describe Database Connection pooling relative to MTS
  14. Describe: In of Process vs. Out of Process component. Which is faster?
  15. Difference between a function and a subroutine, Dynaset and Snapshot, early and late binding, image and picture controls, linked object and embedded Object,listbox and combo box,Listindex and Tab index,modal and moduless window, Object and Class, query unload and unload in form, declaration and instantiation of an object?
  16. Draw and explain Sequence Model of DAO
  17. How can objects on different threads communicate with one another?
  18. How can you force new objects to be created on new threads?
  19. How does a DCOM component know where to instantiate itself?
  20. How do I register a component?
  21. How do I set a shortcut key for label?
  22. What kind of components can be used as DCOM servers?
  23. Name of the control used to call a Windows application
  24. Name the four different cursor and locking types in ADO and describe them briefly
  25. Need of zorder method, no of controls in form, Property used to add a menus at runtime, Property used to count number of items in a combobox,resize a label control according to your caption.
  26. Return value of callback function, The need of tabindex property
  27. Thread pool and management of threads within a thread pool
  28. To set the command button for ESC, Which property needs to be changed?
  29. Type Library and what is it’s purpose?
  30. Types of system controls, container objects, combo box
  31. Under the ADO Command Object, what collection is responsible for input to stored procedures?
  32. What are the ADO objects? Explain them.
  33. What are the different compatibility types when we create a COM component?
  34. What do ByVal and ByRef mean and which is the default?
  35. What does Option Explicit refer to?
  36. What does the Implements statement do?
  37. What is OLE and DDE? Explain.
  38. What is the difference between Msgbox Statement and MsgboxQ function?
  39. What keyword is associated with raising system level events in VB?
  40. What methods are called from the ObjectContext object to inform MTS that the transaction was successful or unsuccessful?
  41. What types of data access have you used.
  42. What was introduced to Visual Basic to allow the use of Callback Functions?
  43. Which controls can not be placed in MDI?
  44. Which controls have refresh method, clear method
  45. Which Property is used to compress a image in image control?
  46. Which property of menu cannot be set at run time?
  47. Which property of textbox cannot be changed at runtime?
  48. What is the maximum size of a textbox?
  49. Which tool is used to configure the port range and protocols for DCOM communications?

COM/COM+ services and components in .NET

# Explain transaction atomicity. We must ensure that the entire transaction is either committed or rolled back.
# Explain consistency. We must ensure that the system is always left at the correct state in case of the failure or success of a transaction.
# Explain integrity. Ensure data integrity by protecting concurrent transactions from seeing or being adversely affected by each other’s partial and uncommitted results.
# Explain durability. Make sure that the system can return to its original state in case of a failure.
# Explain object pooling. With object pooling, COM+ creates objects and keeps them in a pool, where they are ready to be used when the next client makes a request. This improves the performance of a server application that hosts the objects that are frequently used but are expensive to create.
# Explain JIT activation. The objective of JIT activation is to minimize the amount of time for which an object lives and consumes resources on the server. With JIT activation, the client can hold a reference to an object on the server for a long time, but the server creates the object only when the client calls a method on the object. After the method call is completed, the object is freed and its memory is reclaimed. JIT activation enables applications to scale up as the number of users increases.
# Explain role-based security. In the role-based security model, access to parts of an application are granted or denied based on the role to which the callers belong. A role defines which members of a Windows domain are allowed to work with what components, methods, or interfaces.
# Explain queued components. The queued components service enables you to create components that can execute asynchronously or in disconnected mode. Queued components ensure availability of a system even when one or more sub-systems are temporarily unavailable. Consider a scenario where salespeople take their laptop computers to the field and enter orders on the go. Because they are in disconnected mode, these orders can be queued up in a message queue. When salespeople connect back to the network, the orders can be retrieved from the message queue and processed by the order processing components on the server.
# Explain loosely coupled events. Loosely coupled events enable an object (publisher) to publish an event. Other objects (subscribers) can subscribe to an event. COM+ does not require publishers or subscribers to know about each other. Therefore, loosely coupled events greatly simplify the programming model for distributed applications.
# Define scalability. The application meets its requirement for efficiency even if the number of users increases.
# Define reliability. The application generates correct and consistent information all the time.
# Define availability. Users can depend on using the application when needed.
# Define security. The application is never disrupted or compromised by the efforts of malicious or ignorant users.
# Define manageability. Deployment and maintenance of the application is as efficient and painless as possible.
# Which namespace do the classes, allowing you to support COM functionality, are located? System.EnterpriseServices
# How do you make a NET component talk to a COM component? To enable the communication between COM and .NET components, the .NET Framework generates a COM Callable Wrapper (CCW). The CCW enables communication between the calling COM code and the managed code. It also handles conversion between the data types, as well as other messages between the COM types and the .NET types.

.NET and COM interop questions

# Describe the advantages of writing a managed code application instead of unmanaged one. What’s involved in certain piece of code being managed? The advantages include automatic garbage collection, memory management, support for versioning and security. These advantages are provided through .NET FCL and CLR, while with the unmanaged code similar capabilities had to be implemented through third-party libraries or as a part of the application itself.
# Are COM objects managed or unmanaged? Since COM objects were written before .NET, apparently they are unmanaged.
# So can a COM object talk to a .NET object? Yes, through Runtime Callable Wrapper (RCW) or PInvoke.
# How do you generate an RCW from a COM object? Use the Type Library Import utility shipped with SDK. tlbimp COMobject.dll /out:.NETobject.dll or reference the COM library from Visual Studio in your project.
# I can’t import the COM object that I have on my machine. Did you write that object? You can only import your own objects. If you need to use a COM component from another developer, you should obtain a Primary Interop Assembly (PIA) from whoever authored the original object.
# How do you call unmanaged methods from your .NET code through PInvoke? Supply a DllImport attribute. Declare the methods in your .NET code as static extern. Do not implement the methods as they are implemented in your unmanaged code, you’re just providing declarations for method signatures.
# Can you retrieve complex data types like structs from the PInvoke calls? Yes, just make sure you re-declare that struct, so that managed code knows what to do with it.
# I want to expose my .NET objects to COM objects. Is that possible? Yes, but few things should be considered first. Classes should implement interfaces explicitly. Managed types must be public. Methods, properties, fields, and events that are exposed to COM must be public. Types must have a public default constructor with no arguments to be activated from COM. Types cannot be abstract.
# Can you inherit a COM class in a .NET application? The .NET Framework extends the COM model for reusability by adding implementation inheritance. Managed types can derive directly or indirectly from a COM coclass; more specifically, they can derive from the runtime callable wrapper generated by the runtime. The derived type can expose all the method and properties of the COM object as well as methods and properties implemented in managed code. The resulting object is partly implemented in managed code and partly implemented in unmanaged code.
# Suppose I call a COM object from a .NET applicaiton, but COM object throws an error. What happens on the .NET end? COM methods report errors by r

COM interview questions

  1. What is IUnknown? What methods are provided by IUnknown? It is a generally good idea to have an answer for this question if you claim you know COM in your resume. Otherwise, you may consider your interview failed at this point. IUnknown is the base interface of COM. All other interfaces must derive directly or indirectly from IUnknown. There are three methods in that interface: AddRef, Release and QueryInterface.
  2. What are the purposes of AddRef, Release and QueryInterface functions? AddRef increments reference count of the object, Release decrements reference counter of the object and QueryInterface obtains a pointer to the requested interface.
  3. What should QueryInterface functions do if requested object was not found? Return E_NOINTERFACE and nullify its out parameter.
  4. How can would you create an instance of the object in COM? Well, it all depends on your project. Start your answer from CoCreateInstance or CoCreateInstanceEx, explain the difference between them. If interviewer is still not satisfied, you’ll have to explain the whole kitchen behind the scenes, including a difference between local server and inproc server, meaning and mechanism of class factory, etc. You may also mention other methods of object creation like CoGetInstanceFromFile, but discussion will likely turn to discussion of monikers then.
  5. What happens when client calls CoCreateInstance? Again, all depends on the level of detail and expertise of interviewer. Start with simple explanation of class object and class factory mechanism. Further details would depend on a specific situation.
  6. What the limitations of CoCreateInstance? Well, the major problems with CoCreateInstance is that it is only able to create one object and only on local system. To create a remote object or to get several objects, based on single CLSID, at the same time, one should use CoCreateInstanceEx.
  7. What is aggregation? How can we get an interface of the aggregated object? Aggregation is the reuse mechanism, in which the outer object exposes interfaces from the inner object as if they were implemented on the outer object itself. This is useful when the outer object would always delegate every call to one of its interfaces to the same interface in the inner object. Aggregation is actually a specialized case of containment/delegation, and is available as a convenience to avoid extra implementation overhead in the outer object in these cases. We can get a pointer to the inner interface, calling QueryInterface of the outer object with IID of the inner interface.
  8. C is aggregated by B, which in turn aggregated by A. Our client requested C. What will happen? QueryInterface to A will delegate request to B which, in turn, will delegate request for the interface to C. This pointer will be returned to the client.
  9. What is a moniker ? An object that implements the IMoniker interface. A moniker acts as a name that uniquely identifies a COM object. In the same way that a path identifies a file in the file system, a moniker identifies a COM object in the directory namespace.
  10. What’s the difference, if any, between OLE and COM? OLE is build on top of COM. The question is not strict, because OLE was built over COM for years, while COM as a technology was presented by Microsoft a few years ago. You may mention also that COM is a specification, while OLE is a particular implementation of this specification, which in today’s world is not exactly true as well, because what people call COM today is likely implementation of COM spec by Microsoft.
  11. What’s the difference between COM and DCOM? Again, the question does not require strict answer. Any DCOM object is yet a COM object (DCOM extends COM) and any COM object may participate in DCOM transactions. DCOM introduced several improvements/optimizations for distributed environment, such as MULTI_QI (multiple QueryInterface()), security contexts etc. DCOM demonstrated importance of surrogate process (you cannot run in-proc server on a remote machine. You need a surrogate process to do that.) DCOM introduced a load balancing.
  12. What is a dual interface? Dual interface is one that supports both - IDispatch interface and vtbl-based interface. Therefore, it might be used in scripting environment like VBScript and yet to use power and speed of vtbl-based interface for non-scripting environment. Discussion then may easily transform into analyzing of dual interface problems - be prepared to this twist.
  13. Can you have two dual interfaces in one class? Yes. You may have two dual interfaces in one class, but only one of them may be default. The bottom line is that you cannot work with two dual interfaces at the same time due to nature of dual interface! To support two dual interfaces in VB you would write something like:
     dim d1 as IDualInterface1
    dim d2 as IDualInterface2
    set d1 = new MyClassWithTwoDuals
    set d2 = d1

    In ATL’s class you would have to use macro COM_INTERFACE_ENTRY2(IDispatch,
    IDualInterface1), to distinguish between different dual interfaces.

  14. What is marshalling by value? Some objects can essentially be considered static: regardless of which methods are called, the state of the object does not change. Instead of accessing such an object remotely, it is possible to copy the static state of the object and create a new object with the same state information on the caller side. The caller won’t be able to notice the difference, but calls will be more efficient because they do not involve network round trips. This is called “marshaling by value”.
  15. What is a multi-threaded apartment (MTA)? Single-threaded apartment (STA)? This is pretty difficult question to describe shortly. Anyway, apartments were introduced by Microsoft in NT 3.51 and late Windows 95 to isolate the problem of running legacy non-thread safe code into multithreaded environment. Each thread was “encapsulated” into so called single-threaded apartment. The reason to create an object in apartment is thread-safety. COM is responsible synchronize access to the object even if the object inside of the apartment is not thread-safe. Multithreaded apartments (MTA, or free threading apartment) were introduced in NT 4.0. Idea behind MTA is that COM is not responsible to synchronize object calls between threads. In MTA the developer is responsible for that. See “Professional DCOM Programming” of Dr. Grimes et al. or “Essential COM” of Don Box for the further discussion on this topic.
  16. Let’s assume we have object B and aggregated object C (in-proc server), created by B. Can you access any interface of B from C? What’s the difference between aggregated and contained objects? Yes, you can. This is fundamental postulate of COM: “If you can get there from here, you can get there from anywhere”, i.e. QI’ing for IUnknown you may proceed and to get a pointer to any other interface, supported by the object. Aggregated object exposes its interface directly, without visible intervention of the object container. Contained object is created within the object container and its interfaces might be altered or filtered by the object container.
  17. What is ROT ? GIT ? Count pros and cons of both. By definition, running object table (ROT) is a globally accessible table on each computer that keeps track of all COM objects in the running state that can be identified by a moniker. Moniker providers register an object in the table, which increments the object’s reference count. Before the object can be destroyed, its moniker must be released from the table. Global Interface Table (GIT) allows any apartment (either single- or multi-threaded) in a process to get access to an interface implemented on an object in any other apartment in the process.
  18. If you have an object with two interfaces, can you custom marshal one of them? No! The decision to use custom marshaling is an all-or-nothing decision; an object has to custom marshal all its interfaces or none of them.
  19. Is there a way to register in-proc server without regsvr32.exe? Yes. Call DllRegisterServer() from the client. Do not forget to call DLLUnregisterServer() from the same client. You may also use Registrar object for the same purpose or use direct manipulation of the windows registry.
  20. What is VARIANT? Why and where would you use it? VARIANT is a huge union containing automation type. This allows easy conversion of one automation type to another. The biggest disadvantage of VARIANT is size of the union.
  21. How can you guarantee that only remote server is ever created by a client? Create an object (call CoCreateObjectEx()) with CLSCTX_REMOTE_SERVER flag.
  22. What is __declspec(novtable)? Why would you need this? __declspec(novtable) is a Microsoft’s compiler optimization. The main idea of this optimization is to strip the vtable initialization code from abstract class (for abstract class the vtable is empty, while it is initialized in contructor) MSDN has an article on this topic.
  23. What is an IDL? IDL stands for Interface Definition Language. IDL is the language to describe COM interfaces.
  24. What is In-proc? In-proc is in-process COM object, i.e. COM object that implemented as DLL and supposed to be hosted by a container. When you have to instantiate the in-proc object remotely, you may use DLLHost.exe application that was design specially for this purpose.
  25. What is OLE? OLE is an object and embedding first implementation of COM spec available from MS before COM was officially named COM.
  26. Give examples of OLE usage. The most famous examples are probably drag and drop and structured storage implementations.
  27. What are 2 storage types for composite document? Storage and Stream.
  28. Is .doc document a compound document? Is it a structured storage? Compound document is a document that contains information about other documents hosted in this document. All office documents _may_ be compound documents, but may be not. Word documents from version 6.0 and up are stored as structured storage.