(Source? It seems to be an ancestral network)
As a simple and easy-to-use Windows development environment, Visual Basic is popular with the broadcaster of programmers. It makes the programmer no longer have to face complex Windows messages, and the energy can be mainly concentrated in the implementation of program functionality, greatly improves programming efficiency. But everything is beneficial. The high levels of packages and modularity in VB reduces the burden of the programmer, and also enables developers to lose many opportunities to access the low-level API function and interact with Windows. Therefore, compared to the performance efficiency and functionality of the VB application and the program generated by C / C or Delphi. In order to solve this problem, in a large VB development application, the Windows API function directly calls almost inevitable; at the same time, it is possible to develop some dynamic connection libraries to develop some C / C , for use in VB. transfer. This paper mainly discusses the method and rules of the 32-bit dynamic connection library generated by the Windows 95 API function or the user generated in the 32-bit development environment Visual Basic 5.0.
The Windows Dynamic Library is a module containing data and functions, which can be called by other executable files (EXE, DLL, OCX, etc.). Dynamic Library contains two functions: Exported Functions and Internal Functions. Output functions can be called by other modules, while internal functions can only be used inside the dynamic connection library. Although the dynamic connection library can also output data, it is actually used internally. The advantage of using a dynamic connection library is obvious. Extract a part of the function of the application to make a dynamic connection library, not only reduces the size of the primary application, and improves program operation efficiency, but also makes it easier to upgrade. Multiple applications share a dynamic connection library and can effectively save system resources. Because of this, in the Windows system, the dynamic connection library has been used in a lot of use.
In general, dynamic connection libraries are files with DLLs, such as kernel32.dll, commandlg.dll, etc. But there are also exceptions, such as one of the core components of 16-bit Windows, GDI.exe is actually a dynamic library. Write a lot of tools for dynamic connection libraries, such as Visualc , Borlandc , Delphi, etc., for specific methods, see related documents. The following is only taken by Visual C 5.0 as an example, introduce issues that should be noted when developing a dynamic connection library applied to VisualBasic 5.0 (all those involved in the C / C language or compilation environment, all of which are VC5; all It is also an example of VB5 in places involving VisualBasic).
As a 32-bit Windows application development tool, VB5 generated EXE file is naturally 32-bit, usually only 32-bit dynamic connection libraries can be called. However, not all 32-bit dynamic libraries can be properly identified by the EXE file generated by VB. In general, you should pay attention to the following aspects when writing a dynamic connection library for VB applications.
1. Generate a dynamic library to use the __stdcall call convention, instead of using the default __cdecl call convention; __ stdcall conventions are usually used for the call of 32-bit API functions.
2. In the definition file (.def) in the VC5, the function name of the output function must be listed to force the VC5 system to change the decorative name of the output function to a normal function name; the so-called decorative name is a compiler of VC. The output function name generated during the compilation process contains information such as user-defined function names, function parameters, and classes where functions are located. Since the definition file in VC5 is not required, the engine does not include the definition file, VC5 is modified by its own agreement into the output function list, and the output function is generated in VB. In the application, it is not possible to call correctly (unless the ALIAS clause is used). It is therefore necessary to add a .def file, where the user needs the function name, to force the VC5 without outputting the decorative name. 3, the compilation option in the VC5 "structure mem alignment" should be set to 4 bytes, which will be described in detail later.
4. Since the integer variable in C is 4 bytes, the integer variables in VB still have only 2 bytes, so the integer (int) variable declared in C is called in the VB. Integer, and the short integer in C, in the VB; the following table lists the Visual Basic types with the equivalent C language data type. (For 32-bit version of Windows).
C Language Data Type Declare the expression used in VisualBasic as a call
Atom Byval Variable As Integer Results for Integer Types of Expressions
Bool Bool Variable As long result is a long-term expression
Byte byval variable as byte result is a BYTE type expression
Char byval variable as byte result is a BYTE type expression
ColorRef Byval Variable As long result is a long-type expression
DWORD BYVAL VARIABLE AS Long Results for long-type expressions
HWND, HDC, HMENU BYVAL VARIABLE AS long result is a Windows handle such as a long type of expression.
INT, uint byval variable as long result is a long-type expression
Long Byval Variable as long result is a long-type expression
LPARAM BYVAL VARIABLE As long result is a long-type expression
LPDWORD VARIABLE As long result is a long-term expression
LPINT, LPUINT VARIABLE AS long result is a long-term expression
LPRECT VARIABLE AS TYPE Customized Type Arbitrary Variable
LPSTR, LPCSTR BYVAL VARIABLE AS STRING Results for String Types
LPVOID VARIABLE As Any any variable (using Byval when passing the string)
LPWORD VARIABLE AS INTEGER results for Integer type expressions
LRESULT BYVAL VARIABLE AS long result is a long-type expression
NULL As Any or byval Nothing or
BYVAL VARIABLE As Long Byval 0 & or VBnullstring
Short byval variable as integer results for Integer type expressions
Void Sub Procedure is not available
Word Byval Variable AS Integer Results for Integer Types WPARAM BYVAL VARIABLE As long result is a long-type expression
5. When the 32-bit dynamic library is performed in VB, the function name is sensitive. After obtaining the required dynamic connection library, you can call in VB. However, since the VB cannot verify that the application passes whether the application is correct in the dynamic connection library, a large number of API calls in the VB program may reduce the stability of the entire application and will increase the difficulty of post-maintenance. So, decide to be cautious when calling the API function directly in the VB program, but the appropriate use of the API call does effectively improve the performance of the VB program. The balance between this requires programmers to master according to the actual situation. The following is aware of the work that needs to do when the API function is called in VB.
To declare a DLL process, you first need to add a Declare statement in the "General" section of the code window. If the process returns a value, it should be declared as function:
Declare function publicname lib "libname" [alias "alias"] [([Byval] variable [as type] [, [byval] variable [as type]] ...)] as Type
If the process does not return a value, it can be declared as sub:
Declare sub publicname lib "libname" [alias "alias"] [([Byval] variable [as type] [, [byval] variable [as type]] ...)])
By default, the DLL process declared in the standard module can call anywhere in the application. The DLL process defined in other types of modules is the module private, must be declared in front to declare the Private keyword to distinguish. Each component of the statement statement is described below.
(1), designated dynamic library:
The lib clause in the DECLARE statement is used to tell Visual Basic how to find a .dll file containing the process. If the reference process belongs to the Windows core library (user32, kernel32 or gdi32), you can not include a file extension, such as:
Declare function gettickcount lib "kernel32" alias "gettickcount" () AS Long
For other dynamic connection libraries, the path to the lib clarification can be specified:
Declare function lzcopy lib "c: /windows/lzexpand.dll" _
(Byval S as integer, ByVal D AS Integer) AS Long
If you do not specify the path of libName, Visual Basic will find the file in the following order:
1.Exe file location
2 current catalog
3Windows system catalog
4Windows catalog
Directory in the 5Path environment variable
The commonly used operating system environment library files are listed in the table below.
Dynamic Link Library Description
Advapi32.dll advanced API service supports a large number of APIs (including many security and registration calls)
COMDLG32.DLL General dialog API library
GDI32.DLL graphics device interface API library
Kernel32.dllwindows32 bit core API support
LZ32.DLL32 bit compression routine
MPR.dll multi-interface router library
NetApi32.dll32-bit network API library
Shell32.dll32-bit shellapi library
User32.dll user interface routine library
Version.dll repository
Winmm.dllWindows multimedia library
Winspool.drv Background print interface, contains background printing API calls.
For Windows system API functions, you can use the Tools provided by VB API Viewer to find a function and its relevant data structure and constant declarations, and copy it into your own program.
(2) Use an alias:
The Alias clause in the DECLARE statement is an optional part, and the user can reference the function in the dynamic library through the alias it identifies. For example, in the following statement, a function named myfunction in VB is declared, and its initial name in dynamic library mydll.dll is MyFunctionX.
Private declare function myfunction lib "mydll.dll" _
Alias "MyFunctionX" () AS Long
It should be noted that the function name in the Alias clause is sensitive, that is, must be consistent with the declaration of the function (as declared in the C source file). This is because the 32-bit dynamic library is different from the 16-bit dynamic library, where the function name is case sensitive. The same reason, if there is no ALIAS clause, the function name after function (or SUB) is also case sensitive.
Alias clauses are usually used in the following cases:
A. Processing system Windows API processes using strings
If the system Windows API process is called, you must add an Alias clause in the declaration statement to specify the correct character set. The system Windows API function containing strings actually has two formats: ANSI and Unicode (the differences on both ANSI and Unicode are different from the following detailed description). Therefore, in the Windows header file, each function containing a string has an ANSI version and Unicode version. For example, the following is two C language descriptions of the SetWindowText function. It can be seen that the first description defines the function as setWindowTexta, the "A" of the tail indicates that it is an ANSI function:
WinuseraPi Bool WinAPI SetWindowTexta (HWND HWND, LPCSTR LPSTRING);
The second description defines it as setWindowTextw, "W" at the end indicates that it is a Unicode function:
WinuseraPi Bool WinAPI SetwindowTextw (HWND HWND, LPCWSTR LPSTRING);
Because the actual names of the two functions are not "SetWindowText", you must add an Alias clause to the correct function:
Private Declare Function SetWindowText Lib "User32" _Alias "setwindowtexta" (Byval HWNDOTEXTA "(Byval _LPSTRING AS STRING) AS Long
It should be noted that for the system WindowsAPI function used in VB, the ANSI version of the function should be specified, because only WindowsNT supports the Unicode version, and Windows 95 does not support this version. The Unicode version can only be used when the application is only running on the WindowsNT platform.
B. Function name is an inexpensive name
Sometimes, the name of individual DLL processes is not a valid identifier. For example, it may contain illegal characters (such as even characters), or the name is a keyword of VB (such as getObject). In this case, Alias keywords can be used. For example, some process names in the operational environment DLLS will begin with the scribe line. Although the identifier is allowed in the VB identifier, the underscore cannot be used as the first character of the identifier. In order to use this process, you must first declare a name legal process, then use the actual name of the Alias clause process: declare function lopen lib "kernel32" alias "_lopen" _ (byval lppathname as string, Byval IReadwrite_as long) Long
In the above example, LOPEN is the process name used in VB. And _lopen is the name that can be identified in the dynamic connection library.
C. Use the serial number to identify the DLL process
In addition to the name of the name, the serial number can be used to identify the DLL process. Some dynamic connection libraries do not include the name of the process, and serial number must be used when declaring the procedures they contain. Compared to the DLL process identified by the name, if the serial number is used, the memory consumed in the final application will be relatively small, and the speed will be fast. However, the serial number of a specific API may be different in different operating systems. For example, GetWindowsDirectory is 432 under Win95, and is 338 under WindowsNT4.0. All in all, if you want the application to run under different operating systems, it is best not to use the serial number to identify the API process. If the process does not belong to the API, or the application is limited, the serial number is still good.
To use the serial number to declare the DLL process, the string in the Alias clause requires the serial number of the process and add a digital tag character (#) in front of the serial number. For example, the sequence number of the getWindowsDirectory function in Windowskernel is 432; the DLL process can be declared with the following statement:
Declare function getWindowsDirectory lib "kernel32" _ALIAS "# 432" (Byval LPBuffer AS String, _byval nsize as long) AS Long
Here, the name of any legal name can be used, and VB will use the serial number to find the process in the DLL.
In order to obtain the serial number of the process to be declared, you can use the utility such as Dumpbin.exe (Dumpbin.exe is a utility provided by Microsoft Visualc , and its instructions can see the documentation of the VC). With Dumpbin, you can extract various information in the .dll file, such as the list of functions in the DLL, and their serial numbers, and other information related to the code.
(3), use value or reference
In the default, VB passes all parameters (byref) in a reference. This means that there is no actual parameter value, and VB only passes the 32-bit address of the data. There are also many DLL processes to request parameters to pass (byVal). This means they need actual data, not the memory address of the data. If the process requires a pass value parameter, the parameter passed to it is a pointer, then the process will not work correctly because of the wrong data.
To pass the parameters in use, you need to add a Byval keyword in front of the parameter declaration in the DECLARE statement. For example, the InvertRect process requires the first parameter to pass in a pilot value, while the second use of reference mode: Declare function invertRect lib "user32" Alias _ "InvertRecta" (byval HDC As Long, LPRECT AS LONG)
The parameter transmission of the dynamic connection library is a complex issue, and is the most prone to errors when the VB is called dynamic connection library. The declaration of parameter type or delivery method can cause GPF (universal protection errors), even make the operating system crash, so we will discuss this problem in detail later.
(4) Flexible parameter type
Some DLL processes can accept multiple data types. If you need to deliver multiple types of data, you can declare the parameters as ASANY to cancel the type limit. For example, the third parameter in the following declaration (LPPTASANY) can pass an array of Point structures or pass a RECT structure:
Declare function mapwindowpoints lib "user32" alias _ "mapwindowpoints" (Byval Hwndto As Long, LPPT AS Any, _Byval Cpoints as long) AS Long
The ASANY clause provides a certain flexibility, but because it does not perform any type of check, the risk increases. Therefore, when using the ASANY clause, you must carefully check the type of all parameters.
The correct function declaration is a premise of calling a dynamic connection library in VB, but if you want to use it in VB, use a good function in the dynamic library, just a declaration or far less. As mentioned earlier, since the VB cannot verify that the application is passed to whether the parameter value in the dynamic connection library is correct, it is required to understand the parameter type, otherwise it is easy to cause a general purpose protection error or result in potential purposes. BUG, reduce the reliability of the software. The parameter type is divided into simple data types, strings, and three types of customized types.
(1) Simple data type:
The simple data type refers to the NUMERIC data type (including Integer, Long, Single, Double, Currency type), BYTE data type, and Boolean data type. Their common features are simple to structural, and the operating system does not have to be special conversions when processing.
The transfer of simple data type parameters is relatively simple. We know that there are two ways to deliver parameters in VB: BiVAL and inventory (Byref), the default approach is an address. The so-called pass value is transmitted to a specific value of a variable; an address is the address of the transfer variable. For example, in the VB program, the value of a constant variable M = 10 is required into the dynamic library. If the value is used, then the value of the vicinity of the dynamic library is 10, and in the inventive mode, it is incoming. The address of the variable M is equivalent to the value of & M in C / C . It should be noted that the variable of the dynamic connection library is passed in a pass value, and its value cannot be changed in the dynamic library; if you need to modify the value of the incoming parameter in the dynamic connection library, you must use the service mode. In general, a single simple data type is transmitted between VB and dynamic connection libraries, as long as you pay attention to the above aspects. When you need to pass a simple data type through the dynamic library, you must declare the corresponding parameters as an address mode, and then the first element of the array is incorporated, so that in the dynamic connection library, the array is obtained. The first address can be accessed throughout the array. For example, declare a DLL process called ReadArray, requiring incoming an integer array AARRAY: DECLARE FUNCTION READARRAY LIB "MyDLL.DLL" _ (AARRAY AS INTEGER) AS INTEGER
It can be used as follows when calling:
DIM RET, I (5) AS Integer ... Ret = ReadArray (i (0)) '
Passing the entire array into a dynamic connection library
(2) The passage of the string parameters:
Compared with simple data types, the parameters of string types (String, String * N) are more complicated, mainly because of the different strings types used by Windows 95 API and VB. VB uses a String data type called BSTR, which is a data type defined by automation (previously known as ole Automation). A BSTR consists of a head and a string, and the header contains the length information of the string, and the string can contain an embedded NULL value. Most of the BSTR is Unicode, that is, two bytes of each character. BSTR usually ends with two NULL characters of two bytes. The figure below shows a string of a BSTR type.
(Prefix) ATEST / 0 head BSTR points to the first byte of the data
On the other hand, most of the DLL processes (including all processes in the Windows 95 API) use the LPSTR type string, which is a pointer to the criteria ended with NULL, which is also known as the ASCIIZ string. LPSTR has no prefix. The figure below shows a LPSTR pointing to the ASCIIZ string.
ATEST / 0
LPSTR points to the first byte of a string data ending with NULL
If the DLL process requires a LPSTR (pointing to a pointer to the end of NULL) as a parameter, a string can be passed to it in the VB. Because the pointer to the BSTR actually points to the first data byte of the string ended with a null value, it is a LPSTR for the DLL process. In this way, the string of the dynamic connection library can also be modified to it, although it is incorporated by a pass value. Only when the DLL process requires a pointer to the LPSTR, it is incorporated into the string in the way in which the DLL process gets a pointer to the string pointer (equivalent to char ** in C / C ). Instead, the first address of the string used (equivalent to CHAR * in C / C ). When you need to bring a string array to the entire dynamic connection library, the situation becomes more complicated, and the array of conveyance of the simple data type array is to pass the string array. When we pass the first element of a string array in the way, the DLL process is actually the address after the element is pressed into the stack segment, not the first array in the data segment. address. That is, this time the DLL process can only get the first element of the array without accessing the entire array. When the first element is incorporated in an address method, the DLL process can only get pointers to the address of the element in the stack segment, and cannot access the entire array. This can't be said to be a shortcoming of VB. Therefore, in the programming, other methods must be taken if you really need to pass the entire string array into a dynamic library.
We know that in VB, we have a BYTE data type. Each Byte type variable accounts for one byte without a symbol bit, which can be represented by 0 to 255. This data type is specifically used to store binary data. In order to pass the entire string array into the dynamic library, you can save strings with byte arrays. Since BYTE is a simple data type, the passage of byte arrays is very simple. First, you need to correctly transform a string into a byte array. This should involve knowledge of some character sets. Windows 95 and VB use different character sets, the Windows 95 API uses the ANSI or DBCS character set, while VB is used by Unicode character set. The so-called ANSI character set means that each character is represented by one byte, so there can be only 28 = 256 different characters, which is enough for English, but it cannot fully support other languages. The DBCS character set supports many different East Asian languages, such as Chinese, Japanese, and Korean, which uses numbers 0-255 to represent ASCII characters, and other numbers greater than 255 or less indicate that the character belongs to the non-Latin character set; in DBCS, ASCII The length of the character is one byte, while the length of Chinese, Japanese and other East Asian characters is 2 bytes. The Unicode character set completely uses two bytes to represent a character, so up to 216 = 65536 different characters. That is, all characters in the ANSI characters only account for one byte, and the DBCS character set ASCII character accounts for one byte, and the Chinese characters account for two bytes, and each character in the Unicode character set accounts for two bytes. Since VB is different from the character set used by WindowsAPI, after the string to the conversion of the byte array, after the ASC function gets the bytecode of a character, it is necessary to determine whether it is an ASCII character; if it is an ASCII character, Then only one byte in the converted byte array, otherwise two bytes will be taken.
The conversion function is given: getchar byte gets a superb byte or low byte of a character. Its first parameter is a character's ASCII code. The second parameter is the sign to take high byte or low byte; strtobyte Press DBCS or ASI format to convert a string into a byte array, the first parameter is the string to be converted, the second parameter is a fixed length byte array after conversion, and if the array length is not enough to store the entire String, cutting a long section; ChangeStraryTobyte uses the first two functions to convert a string array into a byte array, the first parameter is a string array of fixed length, where each element is a string (each The number of characters contained in the element can be different, the second parameter is a growing byte array, saving the conversion result. Function getcharbyte (byval ishighby as boolean) as Byte 'This function gets a character's high byte or low-byte if ishighbyte tell OneChar> = 0 ThengetCharbyte = Cbyte (OneChar / 256)' right shift 8 digits, Get high byte elsegetcharbyte = cbyte ((OneCharand & H7FFF) / 256) Or & H80END IFEXIT FUNCTIONELSEGETCHARBYTE = CBYTE (OneChar and & HFF) 'Shielding high byte, get low byte exit functionend imp / z
SUB STRTOBYTE (STRTOCHANGE AS STRING, BYTEARRAY () AS BYTE) 'This function converts a string into byte arrays DIM LOWBOUND, UPBOUND AS INTEGERDIM I, Count, Length AS INTEGERDIM Onechar AS Integer
Count = 0Length = len (stratochange) lowbound = lbound (byteArray) Upbound = ubound (byteArray)
For i = lowbound to upboundbytearray (i) = 0 'Initialization byte array NEXT
For i = lowbound to upboundcount = count 1if count <= length tellth, 1))
IF (OneChar> 255) or (OneChar <0) THEN 'This character is a non-ASCII character ByteArray (i) = getcharbyte (one, true)' Get high byte i = i 1if i <= UPBOUND1TEARRAY (i) = Getcharbyte (OneChar, False) 'Get low byte else' This character is ASCII character ByteArray (i) = OneCharend ifelseexit Forend IfNextend Sub
Sub ChangeStraryTobyte (string () AS BYTE) 'Converting a string array into byte arrays DIM Lowbound, UpBound As Integerdim i, Count, StartPos, Maxlen as INTEGERDIM TMPBYTE () AS Byte
Lowbound = lbound (strout) UPBOUND = Ubound (strary) count = 0redim byteary (0)
For i = LowBound To UpBoundMaxLen = LenB (StrAry (i)) ReDim TmpByte (MaxLen 1) ReDim Preserve ByteAry (count MaxLen 1) Call StrToByte (StrAry (i), TmpByte) 'convert a string StartPos = countDoByteAry ( Count = TmpByte (Count - startpos) count = count 1IF Byteary (count - 1) = 0 THEN EXIT DOLOOP 'Corresponding the byte array of each string to fill in the result array in the order of the result arraserve byteary (count - 1 Next IEND SUB
Look at the example of a conversion:
Dimresultary () ASBYTARY () Asstringsomestr (0) = "Test 1" SomeStr (1) = "Test 222" SomeStr (2) = "Test 33" CallChangeStraryTobyte (SomeStr, Resultary) 'converted strings array
When the conversion is completed, check the byte array Resultary, which contain 21 elements, followed by: 178, 226, 202, 212, 49, 0, 178, 226, 202, 212, 50, 50, 50, 0, 178) 226, 202, 212, 51, 51, 0. Among them, [178, 226] is the bytecode of "measurement", [202, 112] is the "test" bytecode, 49, 50, 51, respectively, the ASCII code of characters 1, 2, 3, respectively. It can be seen that after the conversion, the individual elements in the string array is placed in the order in the byte array, and the terminator is separated by termination.
In this way, the string array is converted into a byte array, then simply transmits the first element of the byte array in the address manner, the DLL process can correctly access all the strings in the array. . However, use this method, when the DLL process processing ends back VB, VB is still an array of bytes. If you need to get the string representation represented by the byte array again in the VB, you have to divide the entire byte array to divide a plurality of sub-arrays (each sub-array corresponds to one element in the original string), then Using the VB function StrConv converts each sub-array into a string (the second parameter selected when converting) can be displayed or otherwise. For example, the name of one of the sub-argables is Subary, then the function strconv (Subary, Vbunicode) returns the string it corresponds.
In summary, the passage of the VB application and dynamic library string parameters is a complicated process, which is very cautious when using. At the same time, you should avoid the parameters of the type of array types, as this is easy to cause a serious error such as the subscript, stack overflow.
(3), the user-defined type parameter passed
User-defined types are an important data type in VB, which provides a lot of flexibility for programming, so that developers can construct their own data structure as needed. It is equivalent to structural types in C / C . In VB, the programmer is allowed to pass the custom data type parameters in the way, and the DLL process can also return the modified parameters to the VB program. However, the user-defined type parameters are not supported in the VB. When passing the user-defined type parameters, it is necessary to ensure that the members of the data type in the VB correspond to the structural members in the dynamic library, and the space must be strict. One of the words referred to here, not only means that all structural members in VB must have a corresponding element in the structure of the dynamic library, but also the order defined in the data structure must also be strict, which is used in VB. "Data Structure Member Alignment" is determined. In VB, the data structure uses a double-word alignment (4-byte alignment), so when the user generates a dynamic connection library for VB calls, it must also set the compilation option "Structure Member Alignment" to 4 bytes ( as described above).
The so-called structural member alignment refers to the arrangement of one data structure and its members. For example, in VB, its alignment is 4 bytes, which seems to be divided into many 4-byte size small units in one data structure. If the size of the two or more data members can be placed In a unit, then it is placed; otherwise the unused empty byte may occur in these small units. Let's take a look at a data type:
TYPE TESTTYPEM1 AS INTEGERM2 AS BYTEM3 AS LONGEND TYPE
Its three members have added 2 1 4 = 7. However, since the total length of M1 and M2 is 3, less than 4, they are stored in one unit; but the one byte remaining in the unit is not sufficient to put down a LONG type member M3, so M3 is placed under In a unit, there is an unused empty byte between them; therefore, the actual length of the entire structure is 8 bytes. Similarly, if the position of M3 and M2 is exchanged, the size it takes up is 9 bytes. It can be seen that the order of statements in the structure is also very important.
Typically, when a string does not include a string in a user-defined type, it is not a problem. If only a custom type variable is passed, the variable name can be passed, or the first member of the variable can also be passed, and their effect is the same, and the address of the variable is transmitted into a dynamic library; the same, If you want to pass a custom type array, you can pass the first element of the array, or the first member of the first element can be passed. However, if the user-defined type contains a string type, how do you pass parameters with the dynamic connection library? The answer is regrettable: In VB, you can't customize the user-defined type variable or array of users containing string members, correctly incorporated into the dynamic library. If you do this, even if you have a correct result, you have hidden many fatal dangers behind it. Therefore, if you must include a string variable in the user's custom type, and the type of variable is to be used as a parameter to pass the dynamic library, you'd better modify the type definition, use the string members with the corresponding byte array. Type Replace (Conversion Method can be found foregoing) so that this type of parameters can be passed between VB and dynamic libraries.
In addition, in VB can also pass a function of a function to a dynamic library, the method is not complicated. But the author strongly recommends that it is best not to do it, because the VB application has almost completely lost its own security. If you really need to pass a function pointer, then you have a C / C program to complete this work. In summary, the DLL process in VB is a complicated issue. Programmers must be well grasped to achieve both program efficiency, development of program functions, and do not reduce program security. In addition, it is important to point out that all dynamic connecting libraries mentioned herein refers to a dynamic library that does not use automation (Ole Automation technology), Windows API and most user dynamic connection libraries are this Type of. For dynamic connection libraries that use Ole Automation technology, the way they are passed different, and readers can refer to books about OLE technology, which is no longer involved.