.NET Interoperability Fundamentals

Managed code is great, but sometimes .NET code must call native code, such as Windows API DLLs or COM components; this course will show you how.
Course info
Rating
(146)
Level
Intermediate
Updated
Sep 20, 2014
Duration
5h 45m
Table of contents
Introduction
P/Invoke: The Basics
P/Invoke: Digging Deeper
COM Interop: Foundations
COM Interop: Digging Deeper
COM Interop: Threading
Interop With C++/CLI
Tidbits and Tips
Description
Course info
Rating
(146)
Level
Intermediate
Updated
Sep 20, 2014
Duration
5h 45m
Description

Managed code is great, but sometimes .NET code must call native code, such as Windows API DLLs or COM components. The course explores most options for interop, from P/Invoke, to COM and even C++/CLI. Best practices are spread throughout the course. A deeper understanding of COM mechanisms provides a better experience and the ability to solve issues should they arise. This course should be helpful for any .NET developer that must introp with native code (and vice versa).

About the author
About the author

Pavel is a developer, trainer, author and speaker, specializing in Microsoft technologies. He's the co-author of "Windows Internals, 7th edition" (MS Press, 2017) and "WPF 4.5 Cookbook" (Packt, 2012).

More from the author
More courses by Pavel Yosifovich
Section Introduction Transcripts
Section Introduction Transcripts

Introduction
Hi. My name is Pavel. I'd like to welcome you to the. NET Interoperability Fundamentals course, which I'm going to shorten as. NET Interop. In this course, we'll discuss how. NET code can interoperate with native code. We'll start by talking about some of the basics of the course and what you can expect from it. Then, we'll look at execution modes and how they relate to interoperability scenarios. We'll look at the actual scenarios that are typical for interop to take place, and look at the basic interop mechanisms provided by. NET in the CLR. Finally, we'll sum things up. So, let's begin.

P/Invoke: The Basics
Hi, and welcome to the second module of. NET Interop. In this module, we'll take a look at the basics of Platform Invoke or P/Invoke. We'll look at what P/Invoke is and how to use that. We'll see how to customize DllImport, which is the most import attribute to use when working with P/Invoke, and we'll take a look at first issues, including type conversion, which is very important to do when working with the native code. Then, we'll sum things up prior to moving to the next module, which is going to have some deeper content on Platform Invoke.

P/Invoke: Digging Deeper
Hi. Welcome to module 3 of the. NET Interop course. In this module, we continue our investigation of Platform Invoke. Specifically, I want to show you how to handle errors in P/Invoke calls. We'll see how to handle structures and C-style unions, which are something C# and C that do not provide natively. We'll see how to deal with function pointers that need to call back into our code and look at some interesting issues when working with. NET objects that need to be used by native code and may move because of garbage collection. And, finally, I'll give some general guidance and best practices when working with Platform Invoke. So, let's begin.

COM Interop: Foundations
Hi and welcome to the fourth module of the. NET Interop fundamentals course. In this module, we'll leave the Platform Invoke behind and go over to another very popular interop scenario, which is COM. We'll start by discussing what COM is and what COM isn't. In fact, we'll see many similarities to the. NET world. A lot of stuff coming from COM was actually an inspiration for. NET. We'll discuss interfaces, GUIDs, and HRESULTs, typed libraries and other concepts that are very important to understand in the COM world. Then, we'll see how COM objects get created, which is not such a simple process. However, that's very important to understand, if we need to, for example, solve problems. Some objects that simply don't get created and some errors that we may receive from the. NET side, we need to understand or take a deeper look at how COM works. Finally, at the end of the module, we'll discuss the way to do simple interop from. NET, using the type library information provided by COM. In the next module, we'll take a deeper look at issues and ways to work with COM from the. NET world, but for now, onto the foundations of COM.

COM Interop: Digging Deeper
Hi and welcome to the fifth module of the. NET Interop course. In this module we'll take a deeper look at COM Interop we started discussing in the previous module. First, we'll look at IUnknown interface and how it's used in. NET. We'll take a look at the differences between COM objects and. NET objects in terms of memory management and see how to bridge those differences. We'll take a look at how to work with COM classes which don't have type libraries associated with them. We'll look at how to invoke dynamically COM objects using. NET. And finally, we'll look at how to expose. NET types as COM types for native client's consumption. So let's begin.

COM Interop: Threading
Hi and welcome to module 6 of the. NET Interop course. In this module we'll discuss another aspect of COM Interop known as threading and apartments. We'll start with a brief overview of processes and threads and how they're related. Then, we'll discuss the concept of COM apartments and what they mean. We'll take a look at objects and how apartment placement is important for these kinds of objects. We'll see how. NET deals with the issue of apartments and how we can control client's apartments in. NET applications. Then, we'll take a look at several examples of apartment usage and how they affect the creation of proxies when necessary. And finally, we'll summarize what we've learned.

Interop With C++/CLI
Hi and welcome to module 7 of the. NET Interop course on Pluralsight. In this module we'll look at yet another way to do Interop, this time, using something known as C++/CLI. C++/CLI is really a set of extensions to native C++ that allow us to use and publish. NET code. So, that set of extensions where we can use native and managed code in the same compilation unit, in fact, in the same function even. So we'll take a look at the basic syntax C++/CLI, we'll look at some of the common scenarios to use C++/CLI, and of course we'll take a look at how to take a set of native C++ types and turn them into. NET types that will be usable by any. NET language. So, just be prepared to have some C++ coding in this module. So if you're not familiar with C++ too much, you may have some issues, but you can still get a good sense of what C++/CLI is capable of.

Tidbits and Tips
Hi and welcome to the last module of the. NET Interop course here on Pluralsight. In this module I'll discuss some information tidbits and tips that I'd like to share with you. We'll start by discussing something known as unsafe code, which is although not strictly related to interop, it's still something that's interesting to note in the sense of native code. Then, we'll discuss bitness and see how we should deal with that in interop scenarios. We'll look at some performance tips to enhance or to minimize the effect of the interop layer. We'll look at how COM properties and events are represented in. NET. And we'll take a look at the COM Primary Interop Assembly idea and how type embedding in. NET 4 helps to mitigate that. And finally, we'll summarize the basic things we learned in this course.