First of all, the reader of this article should sell: Yiyan likers who have a considerable Yiyan foundation and are able to skillfully convert commonly used APIs from VB/C declarations to Yiyan DLL commands.
1. Use pointers
For the sake of stability and convenience, Yi Yanyu does not provide pointers directly. This is in progress. It is not very convenient when it comes to advanced vertical. Although there are some third-party support libraries that can remove variable pointers (such as my eLib++ Note: This support library is developed in Delphi, and I am open source. You can go to the Yi Yanyu download area to take a look). But it is not worth it to bring a support library just for this vertical. Actually using an API and some technology can trick Windows and Yising to let them report you a pointer to a variable.
This API is lstrcpyn. Friends who have used C to develop Windows may be familiar with this API, which is string copying. Replaces the C standard library function strncpy under Windows. How can I get variable pointers when copying a string? The secret is the return value of this API:
Look at MSDN: "If the function succeeds, the return value is a pointer to the buffer"
This function doubles the string specified by the second parameter to the string specified by the first parameter, and the third parameter specifies the length of the doubles. If the dual system is successful, return the location of the first parameter (buffer buffer). Have you seen it? It returns the location of the first parameter! ! So if we take the variable of the location to give it the first parameter, and then if we want to get it to make it double-coordinate, will it return to the location of that variable?
Defining a DLL command is as follows:
Dll command: take text pointer
Return value type: integer type
Command name in Dll library: lstrcpyn
Parameters: The text to which it wants to take the pointer Data type: Text type <transfer>
Parameters: The text to which it wants to take the pointer Data type: Text type <transfer>
Parameter: Save Data type: integer type Note: 0
Appropriate this way:
Text 1 = "abcdefg"
Pointer 1 = Take text pointer (text 1, text 1, 0)
Double-code text 1 to yourself, the double-code length is 0 bytes (that is, no double-code), and then return the pointer to text 1. It's that simple. First report to Windows, I want to double-code a text to a memory location, but at the same time report to it, I don't double-code anything, it actually helps you get the pointer to this text.
The above example is to take a pointer to text, and the same is true for other types of variables. Since all types of variables are reflected in the API (actually in memory) as a memory area, the principle is the same. But Yi Yanyu is a forced type of speech, so this time I will cheat Yi Yanyu. Haha, let’s define a new version of this API, just define its parameters as the type you want.
Dll command: take integer pointer
Return value type: integer type
Command name in Dll library: lstrcpyn
Parameters: To get the integer of its pointer Data type: Integer type <Contact address> Note: Must pass address
Parameters: To get the integer of its pointer Data type: integer type <direction> Note: Must pass the address. Repeat double once
Parameter: Save Data type: integer type Note: 0
2. Extraordinary structures are replaced by byte sets
Window98 and the following lines provide a great API: GradientFill, which can easily draw gradient effects.
This API is not very troublesome. Referring to MSDN, we can quickly define this DLL command in Yiyan: (Take gradient fill rectangle as an example)
Dll command: GradientFill
Return value type: logical type
Dll library file name:
Command name in the Dll library: GradientFill
Parameters: hDC Data type: integer type
Parameter: pVertex Data type: TRIVERTEX
Parameters: dwNumVertex Data type: integer type
Parameters: pMesh Data type: GRADIENT_RECT
Parameters: dwNumMesh Data type: integer type
Parameters: dwMode Data type: integer type
The data types that are defined by TRIVERTEX and GRADIENT_RECT:
Self-definition data type: TRIVERTEX
Member: x Data type: integer type
Member: y Data type: integer type
Member: Red Data Type: Short Integer
Member: Green Data type: Short integer type
Member: Blue Data type: Short integer type
Member: Alpha Data type: Short integer type
Self-definition data type: GRADIENT_RECT
Member: UpperLeft Data type: Integer
Member: LowerRight Data type: integer type
According to the MSDN explanation, the basics do not have a title, but if you misappropriate this function, you will not succeed. Why? I report that your reason is in the definition of TRIVERTEX. You might say that this has no title, and the MSDN definition is as follows:
typedef struct _TRIVERTEX { LONG x; Long y; COLOR16 Red; COLOR16 Green; COLOR16 Blue; COLOR16 Alpha; }TRIVERTEX, *PTRIVERTEX;
LONG and Long of C Yan language are 32 bits under Windows 32 bits, corresponding to Yi Yan language "integer type", COLOR16 is sixteen bits, and the "short integer type" corresponding to Yi Yan language has no title! If I report you again, the self-definition data type members in Yi Yan are all four-byte aligned, you should understand. Yes, the members of the self-defined data type in Yi Yan are all four-byte aligned. If they do not exceed four bytes, they will be actively aligned to four bytes. Specifically speaking, Red, Green, Blue, and Alpha are certainly defined as "short integer types", but within Yi Yan, they are all expanded into "integral types". This is the source of the question technique. The key to the solution is to use byte sets instead of self-definition data structures. The byte set of Easy Language does not have a four-byte aligned title.
Dll command: GradientFill
Return value type: logical type
Dll library file name:
Command name in the Dll library: GradientFill
Parameters: hDC Data type: integer type
Parameters: pVertex Data type: Byte set
…… ………………..
That's all. In order to facilitate the production of the required byte set data, I have defined a substep:
Substep: TRIVERTEX to byte set
Return value type: byte set
Note: Due to memory alignment, you must convert the TRIVERTEX type to byte set to apply the API successfully.
Parameters: VertEX Data type: TRIVERTEX <array>
Local variable: number of elements Data type: integer type
Local variable: variable Data type: integer type
Local variable: data Data type: byte set
Number of elements = Take the number of array members (VertEX)
Calculate the first cycle (number of elements, variables)
Data = Data + to byte set (VertEX [Variable].x)
Data = Data + to byte set (VertEX [Variable].y)
Data = Data + to byte set (VertEX [Variable].Red)
Data = Data + to byte set (VertEX [Variable].Green)
Data = Data + to byte set (VertEX [Variable].Blue)
Data = Data + to byte set (VertEX [Variable].Alpha)
Calculate the cycle ()
Return (data)
For details, please see the attached routine
Other APIs with similar characteristics (non-four bytes in parameters or structures) can be solved using the above key points.