COM and .NET Interoperability
Aimed at the more experienced developer who needs to get the old and the new in Windows to coexist,COM and .NET Interoperabilitygives you all the nitty-gritty detail to get .NET Framework code and the older COM standard to work together effectively. Crammed with technical knowledge and a wide range of programming techniques you most likely won't find anywhere else, this book will fill a worthwhile niche as corporations move older Windows code to .NET.The in-depth technical detail of the inner workings of both COM and .NET sets it apart. It says a lot about this title that it is only after 300 pages of introductory material on the inner workings of COM and .NET that the text turns to interoperability between the two. First comes a traditional tour of COM components, including all the gnarly details ofIunknown, GUIDs, type libraries, late binding (andIdispatch), and deployment through the registry. A short section looks at using the Active Template Library (ATL) and its wizards to simplify "traditional" COM components.The author also examines how to build and deploy equivalent components in .NET, along with some more advanced material on reflection, generating on-the-fly code, and assembly information. Material on emulating late-binding in .NET is also a standout here, as this technique is not obvious under the new Windows.At the heart of this book are six chapters showing how to get .NET to call COM code and vice versa, organized into beginning, intermediate, and advanced techniques for each. Core material here shows how to invoke COM objects within .NET, as well as ActiveX controls, a worthy addition, as this is likely to be a workable strategy for .NET developers for years to come. Advanced techniques range further afield. When it comes to calling .NET code from older COM code, apart from the basics of invoking .NET from within "traditional" C++ and Visual Basic, the author also shows how to "consume" new .NET classes like collections within COM.Final sections turn toward other COM+ services, with a full tour of transactions and just-in-time activation (JITA) for building more scalable Windows components. (Here, besides "classic" COM+ components in C++, the author shows how to do it in .NET.) The book rounds out with examples of "fully serviced" Windows components in .NET, including a solid example using a Web service.While COM is destined to wither away, for the next few years there will be ample opportunity for advanced programmers to leverage an in-depth knowledge of COM and .NET. This book's authoritative treatment of most every conceivable permutation of COM and .NET code interaction makes it the definitive resource on the subject. Armed with this title, any advanced C++/C# developer will be able to mix in old code and new code effectively.--Richard DraganTopics covered:Introduction to Platform Invocation (PInvoke) services; calling a traditional DLL from C and C++; using PInvoke to call a traditional DLL with .NET; callback functions in .NET for DLLs; tutorial for COM servers (conventions and built-in interfaces, GUIDs, class factories, deployment); C++ COM clients; IDispatch and scriptable objects; Active Template Library (ATL) basics (including wizard support); COM servers in VB 6; COM IDL files in detail (type libraries and programming reading type info); using C# to view COM type libraries; .NET servers (including assemblies and deployment options); advanced techniques for on-the-fly code generation with theSystem.CodeDOMAPIs; .NET types explained; using .NET reflection APIs (viewing type info in C#); late binding in .NET; basic .NET to COM interoperability (converting COM IDL to .NET types); deploying Interop assemblies; intermediate techniques (including using COM Variants, Param arrays, structures and collections between platforms, events and delegates, error handling); advanced techniques (COM classes implementing .NET interfaces); consuming ActiveX controls in .NET code; modifying Interop assemblies; basic COM to .NET code-sharing techniques (including the COM Callable Wrapper, CCW, thetlbexp.exeutility, COM-aware .NET types); consuming .NET components in VB 6, C++, and VBScript; intermediate COM to .NET techniques (using .NET enumerated types, structures, delegates, and collections within COM); advanced techniques for using .NET in COM (changing type marshaling, custom COM interfaces, defining COM interfaces using managed code, manually defining COM atoms in C#, custom hosts for the .NET runtime); overview of COM+ (including the transactions, pooling, and the COM+ Catalog); classic COM+ components versus .NET equivalentsp; lazy automatic registration; object construction strings; just-in-time activation (JITA); transactional programming in .NET; and sample serviced components (including a Web service example).