# 我有没有写错??

Posted by Rpg之鬼 on April 17, 1998 at 05:02:17:

Option Explicit
Dim APIMem As APIMEMory
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal dst As Any, ByVal src As Any, ByVal size As Long)

Sub Form_Load()

Set APIMem = New APIMEMory

Dim FileSize As Long
Dim ReadString As String
Dim WriteString As String

FileSize = FileLen("c:\program files\vb\winapi\win32api.txt")
APIMem.Memsize = FileSize
APIMem.GAlloc
APIMem.Glock

ReadString = Space(FileSize)
WriteString = Space(FileSize)

Open "c:\program files\adobe\Demon_s\bmp\Ds_01.cg" For Binary Access Read As #1
Get #1, , ReadString
Close #1

Call CopyMemory(APIMem.MemPointer, ReadString, FileSize)
Call CopyMemory(WriteString, APIMem.MemPointer, FileSize)

APIMem.GUnlock
APIMem.GFree
text1.Text = ReadString
End Sub

"ApiMemory.Cls"

Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long

Const GMEM_ZEROINIT = &H40
Const GEMEM_MOVEABLE = &H2

Dim m_MenSize As Long
Dim m_MemHandle As Long
Dim m_MemPointer As Long

Public Property Let Memsize(l As Long)
m_MEMsize = l
End Property
Public Property Get Memsize() As Long
Memsize = m_MEMsize
End Property
Public Property Let Memhandle(l As Long)
m_MemHandle = l
End Property
Public Property Get Memhandle() As Long
Memhandle = m_MemHandle
End Property
Public Property Let MemPointer(l As Long)
m_MemPointer = l
End Property
Public Property Get MemPointer() As Long
MemPointer = m_MemPointer
End Property
Public Sub GAlloc()
m_MemHandle = GlobalAlloc(GEMEM_MOVEABLE Or GMEM_ZEROINIT, m_MEMsize)
End Sub
Public Sub Glock()
m_MemPointer = GlobalLock(m_MemHandle)
End Sub
Public Sub GUnlock()
Dim Throm As Long
Throm = GlobalUnlock(m_MemHandle)
End Sub
Public Sub GFree()
Dim Throm As Long
Throm = GlobalFree(m_MemHandle)
End Sub
Public Function GSize() As Long
GSize = GlobalSize(m_MemHandle)
End Function

请问上述程式是否把"Ds_01.cg"Copy to Memory??
那么Call CopyMemory(WriteString, APIMem.MemPointer, FileSize)又是什么

Follow Ups:

- Re: 我有没有写错?? cww 19:16:19 4/17/98 (0)