Hour 22. Mixing Managed and Unmanaged Code


During the last hour you learned how to utilize COM Interop to communicate between .NET and COM. Although COM is certainly pervasive throughout the operating system, the WIN32 API is still contained in dynamic link libraries and exported as C-style functions with certain calling conventions. Because the WIN32 API was built before .NET came into existence, the API functions obviously all run within an unmanaged environment. Even though the .NET Framework can handle a wide variety of tasks, there may still be times when you need to invoke a function contained within a DLL. Include the fact that you may already have libraries used with some of your current projects, and you can see why this interoperability is important.

There may also be times when you want to write unmanaged code within your managed application. Although this isn't recommended, you may gain a slight performance gain because you are bypassing the common language runtime (CLR) and running native machine code. Visual C++ .NET has an advantage over the other .NET languages because it allows you to easily create a project with a combination of managed and unmanaged code.

In this hour you will learn:

  • How to create and utilize an unmanaged C++ class within a managed application

  • How Platform Invocation (P/Invoke) allows you to call functions within an unmanaged dynamic link library

  • How method signatures are created when custom data types are involved

  • How to change the way parameters are marshaled when using library functions


Sams Teach Yourself Visual C++. NET in 24 Hours
Sams Teach Yourself Visual C++.NET in 24 Hours
ISBN: 0672323230
EAN: 2147483647
Year: 2002
Pages: 237

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net