home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form Form1
- ClientHeight = 4170
- ClientLeft = 60
- ClientTop = 330
- ClientWidth = 6555
- LinkTopic = "Form1"
- ScaleHeight = 4170
- ScaleWidth = 6555
- StartUpPosition = 3 'Windows Default
- Begin VB.CommandButton Command1
- Caption = "Copy String"
- Height = 615
- Left = 1800
- TabIndex = 4
- Top = 3240
- Width = 2775
- End
- Begin VB.Frame Frame2
- Caption = "String Copied from Memory"
- Height = 975
- Left = 120
- TabIndex = 2
- Top = 1680
- Width = 6135
- Begin VB.Label Label2
- Height = 495
- Left = 120
- TabIndex = 3
- Top = 360
- Width = 5895
- End
- End
- Begin VB.Frame Frame1
- Caption = "Original String"
- Height = 975
- Left = 120
- TabIndex = 0
- Top = 360
- Width = 6135
- Begin VB.Label Label1
- Height = 495
- Left = 120
- TabIndex = 1
- Top = 360
- Width = 5775
- End
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Const GMEM_MOVEABLE = &H2
- Const GMEM_ZEROINIT = &H40
- 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 GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
- Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
- Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal dest As Any, ByVal Src As Any, _
- ByVal length As Long)
- Private Sub Command1_Click()
- Dim origStr As String
- Dim copiedStr As String
- Dim strSize As Long
- Dim memHandle As Long
- Dim memPointer As Long
- origStr = "This is the string to be copied into memory."
- Label1.Caption = origStr
- strSize = Len(origStr)
- copiedStr = Space(strSize)
- memHandle = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, strSize)
- memPointer = GlobalLock(memHandle)
- Call CopyMemory(memPointer, origStr, strSize)
- Call CopyMemory(copiedStr, memPointer, strSize)
- Label2.Caption = copiedStr
- GlobalUnlock (memHandle)
- GlobalFree (memHandle)
- End Sub
-