VB from zero start of the supernumerary hanging (12)

Source: Internet
Author: User
Tags integer relative
VB to achieve pointer access! Access to DLLs

--------------------------------------------------------------------------------------------------------------- -----------------------------------------

The CopyMemory function provides an easy way to perform the View access operator (*) in C + +, which accesses the value of the variable to which a pointer variable is directed.
If there is a pointer variable P, in C + + can simply use *p to access, that in VB how to access it?


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) ' Get pointers
Vbgettarget Target,pointer,lenb (Target)
Debug.Print Target

--------------------------------------------------------------------------------------------------------------- -----------------------------------------

For a long time, it has been assumed that only the functions in a standard DLL can be referenced through absolute paths. In fact, you can also use a relative path. It's simple, just try it now.

1) Absolute Path method

For example, your DLL file is located in C:\testDLL\debug\testDLL.dll

Generally speaking, you need to make the following statement in VB

Declare Sub mytest Lib "C:\testDLL\dubug\testDLL.dll" (ByVal x as Long)

Another workaround is to put the TestDLL.dll in the Windows system directory so that you can refer to the file name directly. However, the need to put a file in the Windows system directory, is very uncomfortable!

2) Relative Path method

See how we use relative paths, assuming your DLL file is located in C:\testDLL\debug\testDLL.dll, your VB program is located in the directory C:\testDLL\vbClient
You can make the following statement in VB program:

Declare Sub mytest Lib ". /dubug/testdll.dll "(ByVal x as Long)

If you run your VB program directly, the system will be prompted to error: Can not find. /dubug/testdll.dll.

In order to make the above statement its function, first temporarily closes your VB project. Then use a text editor (NOTEPAD,EDITPLUS,ETC) to open the engineering file (that is, the guy whose suffix is vbp), usually vbp files are made up of several parts.



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.