Copyright statement: You can reprint it at will.Hyperlink formIndicate the source and author information of the following articles andThis statement
Author: Xixi
Source: http://blog.csdn.net/slowgrace/archive/2009/04/24/4105426.aspx
The difference between declaring an API parameter as any and declaring it as long is mentioned in this article. I tried it in this post yesterday. ThanksMyjianPatiently explain.
There is an API function called rtlmovememory. We can have the following two declarations:
Private declare sub copymemory lib "Kernel32" alias "rtlmovememory" (byval destination as long, byval source as long, byval length as long) Private declare sub copymemory lib "Kernel32" alias "rtlmovememory" (destination as any, source as any, byval length as long) |
Then we use the following test code:
Option explicit Private type mystruct X as byte Y as byte Z as long End type Private sub form_load () Dim t as mystruct With T . X = 12 . Y = 34 . Z = & h5678 'stored in memory as & h78 & h56 & H00 & H00 End
Dim P as long Dim B as byte P = varptr (t)
Call copymemory (B, byval P + 2, 1) Debug. Print hex (B)
Call copymemory (B, byval P + 4, 1) Debug. Print hex (B) End sub |
This code roughly means to verify the High-byte alignment storage mode of the structure in VB6.
If the first statement is used, it will cause memory overflow (the consequence of my attempt yesterday is that access is stopped and restarted. The following statement is used:
Call copymemory (B, byval P + 2, 1)
The second parameter of this statement isValues in the P variable(That is, the memory address of the variable t) + the "value" after 2 is passed in, instead ofVariableSo add byval, because byref is used by default in the Declaration. When the Declaration is not declared as byref as any but byval as long, this call can be P + 2, which saves the byval description.
The first parameter of this statement is to pass the address of the variable B over. If the byval as long statement is used, the value of B is passed in (0 at the time ), if you copy data to the address 0, an error will occur. In fact, if we use the byval as long Declaration, we should pass vatptr (B.