Developing and Implementing WindowsR-based Applications with Visual BasicR. NET and Visual StudioR. NET Exam CramT 2 (Exam 70-306)
| In addition to COM and COM+ components , the .NET Framework can access other types of unmanaged code libraries. .NET can call functions from unmanaged Windows API libraries through the use of Platform Invoke (PInvoke), as described in the following steps:
The code in Step 2 demonstrates the PInvoke facility. The Declare statement specifies the name of the API call ( GetComputerName ), the name of the library that contains the call ( kernel32 ), and the parameters to the API call ( lpBuffer and nSize ).
As you've seen in this chapter, you have a variety of ways to call non-.NET code from your .NET applications. When you're working with .NET, your long- term goal should be to translate your entire application into native .NET code. Particularly when you're upgrading an existing application, though, it can be very useful to call legacy components from your new code. |