Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does VB.NET platform call perform operations?

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you the "VB.NET platform call is how to perform the operation", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "VB.NET platform call is how to perform the operation" this article.

Windows API is the abbreviation of API function of Windows system (Application Program Interface, that is, application program interface function). It is some common functions provided by Windows operating system to all kinds of development languages for developing application software based on Windows platform. These functions are generally at the bottom, so when various development languages can not solve the problem by using their own functions or class libraries, calling Windows API functions is often a very direct and effective solution. However, because calling the Windows API function in the program is generally very complex, whether the programmer can use the Windows API function flexibly or not is often an important sign of its level. However, since Microsoft launched the .NET Framework, various programming languages based on the .NET platform, such as VB.NET and Visual C#, seldom use Windows API functions, and Microsoft does not advocate the use of Windows API functions in these .NET development languages as before, the main reasons are as follows:

1. The class library .NET Framework SDK that comes with the .NET Framework is a rich and powerful software development package, and almost all the functions implemented by various Windows API functions can be found in this software development package.

two。 The purpose of Microsoft VB.NET, Visual C # and so on is to write cross-platform applications. If Windows API functions are used in VB.NET, Visual C #, etc., it is doomed that the written programs can only run under the Windows platform, while weakening the cross-platform ability of .NET. This is why Microsoft does not advocate calling Windows API functions on the VB.NET platform.

Although Microsoft does not advocate calling Windows API functions in VB.NET and Visual C #, because the .NET Framework has been launched for a short time, the class libraries provided in .NETFrameWork SDK are not enough to completely replace all the functions of Windows API functions, so in some cases, the .NET development language still has to call Windows API functions.

Introduction to VB.NET platform call, managed DLL, and unmanaged DLL:

A managed DLL is a file that can be referenced directly in the common language runtime (Common Language Runtime, referred to as CLR) and has the extension "DLL". Specifically, it refers to the DLL file that encapsulates various namespaces, such as System.dll and so on. Unmanaged DLL is the usual dynamic link library, which includes DLL files that encapsulate all Windows API functions. Functions in various unmanaged DLL cannot be called directly in the common language runtime, but can only be called through the platform provided by the .NET Framework.

Platform invocation is a service provided by the .NET Framework for .NET development languages such as VB.NET and Visual C # to introduce various functions encapsulated in unmanaged DLL (including Windows API functions) into managed code. Platform invocation relies on metadata to find the exported function and encapsulate its parameters at run time.

Flowchart of the common language runtime invoking functions in unmanaged DLL using platform services

When you use the platform invocation service in managed code to invoke a function encapsulated in an unmanaged DLL, the platform service does the following in turn:

1. Find the DLL file that contains the function.

two。 If found, the DLL file is loaded into memory.

3. Find the address of the function in memory, push its parameters onto the stack, and marshal the required data.

4. Transfer control to an unmanaged function. In this way, the entire function call is complete.

When calling a service on the VB.NET platform, it is stated that there are two main ways to implement the Windows API function:

1. Use the DllImport feature class to declare the Windows API function.

two。 Use the "Declare" statement to declare the Windows API function.

Although these two methods have the same effect, they are very different in complexity and simplicity. The declaration process of * method is more complex, and it is easy to make mistakes in declaring Windows API function, so it is not recommended. The second method is relatively simple and preserves a lot of syntax from previous Visual Basic, so it is usually used to declare Windows API functions.

The above is all the contents of the article "how VB.NET platform calls operate". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report