怎么总是显示地址不显示地址中的内容
用copymemory函数把指针指向的数据读出来,怎么读出来的是地址不是那个地址里面的内容啊 你确定按值传递了参数? 确定你的参数使用都是正确的。这个数据是储存在外部设备中 外部设备提供了API函数获得了存储数据的缓冲区指针
想用copymemory函数把数据提出来 但是显示的不是储存的内容
缓冲区指针是个自定义的变量 dim a as SP_DATA_BUFFER
TYPE SP_DATA_BUFFER
data(255) as byte
END TYPE
现在不知道怎么使用copymemory才能把数据准确的读出来 copymemory是在计算机的内存里操作,和外部设备没关系.
你要先从外部设备把数据读取到计算机里,在考虑copymemory
外部设备提供api获得了存储数据的缓冲区指针....这个指针怕是用来在读取设备数据的时候作为参数的吧...这个指针对于计算机来说没有意义,对设备才有意义
'Example Name: Maintaining Form Aspect Ratio During Resizing
'------------------------------------------------------------------------------
' BAS Module Code
'------------------------------------------------------------------------------
Option Explicit
Public defWindowProc As Long
Private Const GWL_WNDPROC As Long = (-4)
Private Const WM_DESTROY = &H2
Private Const WM_SIZING = &H214
'wParam for WM_SIZING message
Private Const WMSZ_LEFT = 1
Private Const WMSZ_RIGHT = 2
Private Const WMSZ_TOP = 3
Private Const WMSZ_TOPLEFT = 4
Private Const WMSZ_TOPRIGHT = 5
Private Const WMSZ_BOTTOM = 6
Private Const WMSZ_BOTTOMLEFT = 7
Private Const WMSZ_BOTTOMRIGHT = 8
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" _
Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(hpvDest As Any, _
hpvSource As Any, _
ByVal cbCopy As Long)
Public Sub Unhook(fhwnd As Long)
If defWindowProc Then
Call SetWindowLong(fhwnd, GWL_WNDPROC, defWindowProc)
defWindowProc = 0
End If
End Sub
Public Sub Hook(fhwnd As Long)
defWindowProc = SetWindowLong(fhwnd, _
GWL_WNDPROC, _
AddressOf WindowProc)
End Sub
Function WindowProc(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Dim rc As RECT
Select Case uMsg
Case WM_SIZING
CopyMemory rc, ByVal lParam, LenB(rc)
Select Case wParam
Case WMSZ_LEFT
rc.Bottom = (rc.Right - rc.Left) + rc.Top
CopyMemory ByVal lParam, rc, LenB(rc)
WindowProc = 1
Case WMSZ_RIGHT
rc.Bottom = (rc.Right - rc.Left) + rc.Top
CopyMemory ByVal lParam, rc, LenB(rc)
WindowProc = 1
Case WMSZ_TOP
rc.Right = (rc.Bottom - rc.Top) + rc.Left
CopyMemory ByVal lParam, rc, LenB(rc)
WindowProc = 1
Case WMSZ_BOTTOM
rc.Right = (rc.Bottom - rc.Top) + rc.Left
CopyMemory ByVal lParam, rc, LenB(rc)
WindowProc = 1
Case WMSZ_TOPLEFT
rc.Left = (rc.Top - rc.Bottom) + (rc.Right)
CopyMemory ByVal lParam, rc, LenB(rc)
WindowProc = 1
Case WMSZ_TOPRIGHT
rc.Right = (rc.Bottom - rc.Top) + rc.Left
CopyMemory ByVal lParam, rc, LenB(rc)
WindowProc = 1
Case WMSZ_BOTTOMLEFT
rc.Bottom = (rc.Right - rc.Left) + (rc.Top)
CopyMemory ByVal lParam, rc, LenB(rc)
WindowProc = 1
Case WMSZ_BOTTOMRIGHT
rc.Bottom = (rc.Right - rc.Left) + rc.Top
CopyMemory ByVal lParam, rc, LenB(rc)
WindowProc = 1
End Select
Case WM_DESTROY:
If defWindowProc <> 0 Then
Call Unhook(form1.hwnd)
End If
End Select
'处理windows消息
WindowProc = CallWindowProc(defWindowProc, _
hwnd, _
uMsg, _
wParam, _
lParam)
End Function
'------------------------------------------------------------------------------
' Form Code
'------------------------------------------------------------------------------
'在Form中需要一个Command Button(Command1)
Option Explicit
Private Sub Form_Load()
With form1
.Width = 6000
.Height = 6000
Call Hook(.hwnd)
End With
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call Unhook(Me.hwnd)
End Sub
也就是说指针指向的是这个结构.
那试试这样吧:
call copymemory(byval varptr(a),byval [保存指针值的变量],lenb(a))
补充:VB , API