home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch12 / readtext / readtext.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-02-20  |  2.8 KB  |  81 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    ClientHeight    =   4170
  4.    ClientLeft      =   60
  5.    ClientTop       =   330
  6.    ClientWidth     =   6555
  7.    LinkTopic       =   "Form1"
  8.    ScaleHeight     =   4170
  9.    ScaleWidth      =   6555
  10.    StartUpPosition =   3  'Windows Default
  11.    Begin VB.CommandButton Command1 
  12.       Caption         =   "Copy String"
  13.       Height          =   615
  14.       Left            =   1800
  15.       TabIndex        =   4
  16.       Top             =   3240
  17.       Width           =   2775
  18.    End
  19.    Begin VB.Frame Frame2 
  20.       Caption         =   "String Copied from Memory"
  21.       Height          =   975
  22.       Left            =   120
  23.       TabIndex        =   2
  24.       Top             =   1680
  25.       Width           =   6135
  26.       Begin VB.Label Label2 
  27.          Height          =   495
  28.          Left            =   120
  29.          TabIndex        =   3
  30.          Top             =   360
  31.          Width           =   5895
  32.       End
  33.    End
  34.    Begin VB.Frame Frame1 
  35.       Caption         =   "Original String"
  36.       Height          =   975
  37.       Left            =   120
  38.       TabIndex        =   0
  39.       Top             =   360
  40.       Width           =   6135
  41.       Begin VB.Label Label1 
  42.          Height          =   495
  43.          Left            =   120
  44.          TabIndex        =   1
  45.          Top             =   360
  46.          Width           =   5775
  47.       End
  48.    End
  49. Attribute VB_Name = "Form1"
  50. Attribute VB_GlobalNameSpace = False
  51. Attribute VB_Creatable = False
  52. Attribute VB_PredeclaredId = True
  53. Attribute VB_Exposed = False
  54. Option Explicit
  55. Const GMEM_MOVEABLE = &H2
  56. Const GMEM_ZEROINIT = &H40
  57. Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
  58. Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
  59. Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
  60. Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
  61. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal dest As Any, ByVal Src As Any, _
  62.                                                 ByVal length As Long)
  63. Private Sub Command1_Click()
  64.     Dim origStr As String
  65.     Dim copiedStr As String
  66.     Dim strSize As Long
  67.     Dim memHandle As Long
  68.     Dim memPointer As Long
  69.     origStr = "This is the string to be copied into memory."
  70.     Label1.Caption = origStr
  71.     strSize = Len(origStr)
  72.     copiedStr = Space(strSize)
  73.     memHandle = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, strSize)
  74.     memPointer = GlobalLock(memHandle)
  75.     Call CopyMemory(memPointer, origStr, strSize)
  76.     Call CopyMemory(copiedStr, memPointer, strSize)
  77.     Label2.Caption = copiedStr
  78.     GlobalUnlock (memHandle)
  79.     GlobalFree (memHandle)
  80. End Sub
  81.