Use the. NET Framework class to replace API call -- Zt

Source: Internet
Author: User
Tags win32
Abstract: by learning some specific and useful classes in the Microsoft. NET framework, you can reduce your dependencies on Win32 API calls. Each class discussed in this article can be called in place of one or more Win32 APIs. In Microsoft Visual Basic 6.0, you must call one or more Win32 APIs to complete the same task.
The target searches for specific alternatives for existing Win32 API calls.
Understand the Registry class.
Use the FileVersionInfo class.
Use environment information and system information.
Directory to avoid the use of Win32 API to use the registry to retrieve file version information. Search environment information summary to avoid the use of Win32 API
If you are a Microsoft Visual Basic® 6.0 developer, you cannot avoid calling Win32 APIs. Developers have too many tasks to complete, but Visual Basic cannot provide any implementation methods. For example, in Visual Basic 6.0, it is difficult to complete the following tasks: determine the file version information.
Read and write data anywhere in the registry.
Determine your specific folders, such as Microsoft Windows® favorites or personal folders.
Retrieve the list of all available drives.
Find the user's login name or computer name.
Retrieve the list of all opened windows.
If you only use the tools provided in Visual Basic 6.0, you cannot solve any of the preceding problems. For each problem, developers need to use Windows APIs. Many developers have found a way to complete these (and many others) tasks using the Windows API.
What are the problems with Windows APIs?
Why not continue using Windows APIs in the. NET environment? If you use the. NET platform to call a service (called "P/Invoke"), you can certainly do so. From the perspective of Visual Basic developers, calling Windows APIs is not more difficult than using the Declare statements they are familiar. However, using Windows APIs in the. NET environment has some serious defects. You may need to consider taking any feasible measures to avoid these problems. For example:
. NET public language runtime is not affected by the platform. When you use a Windows API call, you bind the code to a specific platform for code writing (that is, compared to a specific Windows version of another operating system or Windows itself ). If necessary, you need to convert the code to another platform. In this case, you need to modify each line of code called using the API.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.