In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "VB how to call dynamic link library", 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 how to call dynamic link library" this article.
VB has a lot to learn. Here we mainly introduce VB calls to dynamic link libraries, including the expressions used when C language data types are declared as calls in Visual Basic.
As an easy-to-use Windows development environment, Visual Basic has been welcomed by the majority of programmers since it was launched. It makes programmers no longer have to face numerous and complicated Windows messages directly, but can focus on the implementation of program functions, which greatly improves the programming efficiency. But everything has its advantages and disadvantages. The high degree of encapsulation and modularization in VB lightens the burden on programmers and deprives developers of many opportunities to access low-level API functions and interact directly with Windows. Therefore, in comparison, the execution efficiency and functionality of VB applications are lower than those generated by Cpicket + or Delphi. In order to solve this problem, in a large-scale VB development application, it is almost inevitable to call Windows API function directly; at the same time, programmers may need to develop some dynamic link libraries by themselves, such as C _ Windows API +, which can be used to call dynamic link libraries in VB. This paper mainly discusses the methods and rules of directly calling Windows 9***PI function or user-generated 32-bit dynamic link library in 32-bit development environment Visual Basic 5.0.
Windows dynamic link library is a module containing data and functions, which can be called by other executable files (EXE, DLL, OCX, etc.). Dynamic link libraries contain two kinds of functions: output (exported) function and internal (internal) function. The output function can be called by other modules, while the internal function can only be used within the dynamic link library. Although a dynamic link library can also output data, in fact its data is usually used only internally. The advantages of using dynamic link libraries are obvious. Part of the functions of the application program are extracted to make a dynamic link library, which not only reduces the size of the main application, improves the running efficiency of the program, but also makes it easier to upgrade. Sharing a dynamic link library among multiple applications can also effectively save system resources. Because of this, dynamic link libraries are widely used in Windows systems.
Generally speaking, dynamic link libraries are files with the extension DLL, such as Kernel32.dll, commdlg.dll, and so on. But there are exceptions, such as GDI.exe, one of the core components of 16-bit Windows, is actually a dynamic library. There are many tools to write dynamic link libraries, such as VisualC++, BorlandC++, Delphi and so on. Specific methods can be found in the relevant documents. Here is a brief introduction to the issues that should be paid attention to when developing a dynamic link library applied to VisualBasic5.0, taking Visual Clipper 5.0 as an example (VC5 is used as an example for all places in this article that involve the language or compiler environment of VisualBasic5.0, and VB5 is used for all places involving VisualBasic).
As a development tool for 32-bit Windows applications, the exe files generated by VB5 are naturally 32-bit, and usually only 32-bit dynamic link libraries can be called. However, not all 32-bit dynamic libraries are correctly recognized by exe files generated by VB. Generally speaking, when you write dynamic link libraries for VB calls, you should pay attention to the following aspects:
1. When generating a dynamic library, use the _ _ stdcall calling convention instead of the default _ _ cdecl calling convention; the _ _ stdcall convention is usually used to call 32-bit API functions.
2. In the definition file (.def) in VC5, the function name of the output function must be listed in order to force the VC5 system to change the decorative name (decoratedname) of the output function into a normal function name; the so-called decorative name is the output function name generated by the VC compiler during compilation, which contains user-defined function name, function parameters and function class and other information. Because the definition file in VC5 is not required, when the project does not contain a definition file, VC5 will change the user-defined output function name to a decoration name and put it in the output function list according to its own convention. Such an output function cannot be called correctly in the application generated by VB (unless the Alias clause is used when declaring). So you need to add a .def file that lists the function names the user needs to force VC5 not to output by decorative name.
3. The compilation option "structure member alignment (structure member alignment)" in VC5 should be set to 4 bytes, which will be described in detail later.
4. Because the integer variable in C is 4 bytes, while the integer variable in VB is still only 2 bytes, the int variable declared in C should be declared as long integer (long) when called in VB, while the short integer (short) in C should be declared as integer in VB. The following table lists the equivalent Visual Basic types for the most commonly used C language data types (for 32-bit versions).
The C language data type is declared in Visual Basic as the expression used when calling
The result of ◆ ATOM ByVal variable As Integer is an expression of type Integer
The result of ◆ BOOL ByVal variable As Long is an expression of type Long
The result of ◆ BYTE ByVal variable As Byte is an expression of type Byte
The result of ◆ CHAR ByVal variable As Byte is an expression of type Byte
The result of ◆ COLORREF ByVal variable As Long is an expression of type Long
The result of ◆ DWORD ByVal variable As Long is an expression of type Long
◆ HWND, HDC, HMENU ByVal variable As Long results in Windows handles such as expressions of type Long
◆ INT, the UINT ByVal variable As Long result is an expression of type Long
The result of ◆ LONG ByVal variable As Long is an expression of type Long
The result of ◆ LPARAM ByVal variable As Long is an expression of type Long
The result of ◆ LPDWORD variable As Long is an expression of type Long
◆ LPINT, the LPUINT variable As Long result is an expression of type Long
Any variable of the custom type of ◆ LPRECT variable As type
◆ LPSTR, the LPCSTR ByVal variable As String result is an expression of type String
◆ LPVOID variable As Any any variable (use ByVal when passing strings)
The result of ◆ LPWORD variable As Integer is an expression of type Integer
The result of ◆ LRESULT ByVal variable As Long is an expression of type Long
◆ NULL As Any or ByVal Nothing or
◆ ByVal variable As Long ByVal 0 & or VBNullString
The result of ◆ SHORT ByVal variable As Integer is an expression of type Integer
◆ VOID Sub procedure is not available
The result of ◆ WORD ByVal variable As Integer is an expression of type Integer
The result of ◆ WPARAM ByVal variable As Long is an expression of type Long
5. When declaring a 32-bit dynamic library in VB, the function name is case-sensitive. Once you have the dynamic link library you need, you can call the dynamic link library in VB. However, because VB cannot verify whether the parameter values passed by the application to the dynamic connection library are correct, a large number of API calls in VB programs may reduce the stability of the entire application and increase the difficulty of maintenance in the future. Therefore, you should be careful when deciding to call the API function directly in the VB program, but the proper use of API calls can effectively improve the performance of the VB program. This balance needs to be mastered by programmers according to the actual situation.
These are all the contents of the article "how to call the dynamic Link Library by VB". 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.