VB analog pointer module mpoint. Bas

Source: Internet
Author: User

'File: mpoint. Bas
'Name: VB analog pointer Module
'Author: zyl910
'Version: v1.2
'Updata: 2005-8-28
'E-mail: zyl910@sina.com

'Features & features:
'1. Create a simulated pointer in the stack. This allows recursion and multithreading.
'2. Allow compilation optimization. In addition, this kind of simulated pointer construction method is the fastest in stack creation and compilation optimization.
'3. the pointer can be used as an array like a C/C ++ pointer
'4. Allow negative addressing. This helps image convolution, scaling, and rotation.
'5. The element size and step size are allowed to be different. (Yes for byte, as if single is not)
'6. compatible with the vbboost library. The arrayowner of the vbboost library is implemented with lightweight objects and is easy to use. However, it is not suitable for complex addressing and speed requirements for massive data processing (such as processing ).

'Note:
'1. String and object are both reference data types. Do not use it easily unless you know it very well.
'2. When initializing the address, do not directly change safearray1d. pvdata to modify the address. The PTR attribute should be used. This is universal.
'3. Do not superstitious PTR attributes. In the loop, you can use the address continuity optimization code (directly modify safearray1d. pvdata)

 

Option explicit

'####################################### ##########
### Const constant ###################################
'####################################### ##########

### Global compilation constant #################################
'Set the Conditional compilation parameters in the Project Properties dialog box"

'= [Matthcw Curland] vbboost ==========================
'Novboost: indicates whether the vbboost library exists.

'= [Zyl910] api library ==========================
'Includeapilib: the api library is referenced. You do not need to manually write the API declaration at this time.

 

'####################################### ##########
### Win32 API ################################### #
'####################################### ##########

Private declare sub copymemory lib "kernel32.dll" alias "rtlmovememory" (destination as any, source as any, byval length as long)

 

# If novboost and (includeapilib = 0) then

Public declare function varptrarray lib "msvbvm60.dll" alias "varptr" (VAR () as any) as long

Public type safearray
What are the dimensions of the cdims as integer array?
What are the features of the ffeatures as integer array?
What is the size of each element of the cbelements as long array?
How many times have the clocks as long 'array been locked?
Where is the data in the array pvdata as long?
'Rgsabound () as sfarraybound
End type
Public type safearraybound
How many elements does celements as long have in one dimension?
Llbound as long 'How many times does the index start?
End type
Public type safearray1d
Cdims as integer
Ffeatures as integer
Cbelements as long
Clocks as long
Pvdata as long
How many elements does celements as long have in one dimension?
Llbound as long 'How many times does the index start?
End type

Public const fadf_auto as integer = & H1
Public const fadf_static as integer = & H2
Public const fadf_embedded as integer = & h4
Public const fadf_fixedsize as integer = & H10
Public const fadf_record as integer = & H20
Public const fadf_haveiid as integer = & h40
Public const fadf_havevartype as integer = & h80
Public const fadf_bstr as integer = & h100
Public const fadf_unknown as integer = & h200
Public const fadf_dispatch as integer = & H400
Public const fadf_variant as integer = & h800
Public const fadf_reserved as integer = & hf008

# End if '# If novboost then

 

'####################################### ##########
'####################################### ##########
'####################################### ##########

 

'Function: Construct a simulated pointer
'Parameter:
'Parray: Address of the safearray structure of the array (Return Value of varptrarray (array name ). Must be an empty Dynamic Array
'Sa: A safearray1d used to save the simulated pointer description.
'Itemsize: the length of the array element (occupied byte, for example, byte type 1). The element size and step size are different.
'Llbound: lower bound to the array
'Celements: number of items in the array (Upper Bound = Lower Bound + number of items-1)
'Return value: whether the request is successful
Public Function makepoint (byval parray as long ,_
Byref SA as safearray1d, byval itemsize as long ,_
Optional byval llbound as long = 0 ,_
Optional byval celements as long = & h7fffffff) as Boolean
If parray = 0 Then exit function

With SA
. Cdims = 1
. Ffeatures = fadf_auto or fadf_fixedsize
. Cbelements = itemsize
. Clocks = 0
. Pvdata = 0
. Llbound = llbound
. Celements = celements
End
Copymemory byval parray, varptr (SA), 4

Makepoint = true

End Function

'Function: release a simulated pointer
'Parameter:
'Parray: Address of the safearray structure of the array (Return Value of varptrarray (array name)
'Return value: whether the request is successful
Public Function freepoint (byval parray as long) as Boolean
If parray = 0 Then exit function

Copymemory byval parray, 0 &, 4

Freepoint = true

End Function

'Set the address of the simulated pointer
'Parameter:
'Sa: The safearray structure of a simulated pointer
Public property get PTR (byref SA as safearray1d) as long
PTR = sa. pvdata-sa. llbound * Sa. cbelements
End Property

Public property let PTR (byref SA as safearray1d, byval RHS as long)
SA. pvdata = RHS + SA. llbound * Sa. cbelements
End Property

'Get the dimension of the array
Public Function getarraydims (byval parray as long) as integer
Dim PSA as long
Dim cdims as integer

If parray = 0 Then exit function

Copymemory PSA, byval parray, 4
Copymemory cdims, byval clng (psa + 0), 2

Getarraydims = cdims

End Function

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.