VB plug-ins from scratch (12)

Source: Internet
Author: User
VB implements pointer access! DLL access
Certificate --------------------------------------------------------------------------------------------------------------------------------------------------------
The CopyMemory function provides a simple method for executing the insight access operator (*) in C ++. This operator can access the value of a variable pointed to by a pointer variable.
That is to say, if there is a pointer variable P, you can simply use * P to access it in C ++. How can we access it in VB?
In VB, we can use the CopyMemory function alias.
Declare Sub VBGetTarget Lb "kernel32" Alias "RtlMoveMemory" (Target As Any, ByVal lPoint As Long, ByVal cbCopy As Long)
Example:
Dim Pointer As Long
Dim Target As Integer
Dim I As Integer
I = 123.
Pointer = VarPtr (I) 'to get the Pointer
VBGetTarget Target, Pointer, LenB (Target)
Debug. Print Target
Certificate --------------------------------------------------------------------------------------------------------------------------------------------------------
For a long time, it has been considered that functions in standard DLL can only be referenced through absolute paths. In fact, you can also use relative paths. It's very easy. Now let's try it.
1) absolute path method
For example, your DLL file is located in c: estDLLdebugestDLL. dll.
In general, you need to make the following statement in VB:
Declare Sub mytest Lib "c: estDLLdubugestDLL. dll" (ByVal x As Long)
Another work und is to place testDLL. dll in the windows system directory so that you can directly reference the file name. However, it is uncomfortable to put a file under the windows system directory!
2) relative path method
Let's see how to use the relative path. Assume that your DLL file is located in c: estDLLdebugestDLL. dll, and your vbprogram is located in the directory c: estDLLvbClient.
You can make the following statement in the vbprogram:

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.