Results 1 to 5 of 5

Thread: Direct Memory Access in VB - sample code

  1. #1
    jim mcnamara
    Guest

    Direct Memory Access in VB - sample code

    Code:
    Option Explicit
    
    ' this code works under VB 6, will work under VB 5 with mods
    ' the GetMem functions work under NT 4 & Windows 2000, but you cannot access BIOS 
    '    memory on NT 4 or NT 5 machines.  So don't try....
    ' requires a textbox named Text1 on your form.
    
    Private Declare Sub GetMem1 Lib "msvbvm60.dll" (ByVal lAddress As Long, var As Byte)
    
    ' GetMem2, GetMem4 and GetMem8 functions read 2, 4, & 8 bytes of memory
    ' GetMem2  & GetMem4 are usable by VB
    
    Private Declare Sub GetMem2 Lib "msvbvm60.dll" (ByVal lAddress As Long, var As Integer)
    Private Declare Sub GetMem4 Lib "msvbvm60.dll" (ByVal lAddress As Long, var As Long)
    
    ' NOTE:
    
    ' For VB 5.0 change the "msvbvm60.dll" to msvbvm50.dll
    
    ' I'm not using these api's; they write memory and are included for completeness.
    ' Two words: WATCH OUT
    ' if you elect to use these, you are on your own...
    
    Private Declare Sub PutMem1 Lib "msvbvm60.dll" (ByVal lAddress As Long, var As Byte)
    Private Declare Sub PutMem2 Lib "msvbvm60.dll" (ByVal lAddress As Long, var As Integer)
    Private Declare Sub PutMem4 Lib "msvbvm60.dll" (ByVal lAddress As Long, var As Long)
    
    
    Private Sub Form_Load()
      Text1.Text = BIOSDateString
    End Sub
    
    Private Function BIOSDateString() As String
      Dim b As Byte
      Dim AddrMem As Long
      Dim strTmp As String
      Dim i As Integer
      
      AddrMem = &HFFFF5
      strTmp = ""
      For i = 0 To 7
          Call GetMem1(AddrMem + i, b)
          strTmp = strTmp & Chr$(b)
      Next
      BIOSDateString = strTmp
    End Function
    Have fun.


  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Great code Jim!
    VB and BIOS , very nice.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Jim that trashed the thread it was running in, I tried it twice. VB6 NT4. Any ideas?

  4. #4
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    but you cannot access BIOS 
    '    memory on NT 4 or NT 5 machines.  So don't try....
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  5. #5
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Hmmm, oh well *shrug*.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width