Author Topic: continuation Load&Save  (Read 2640 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
continuation Load&Save
« on: March 01, 2011, 03:06:32 PM »
Deleted...
« Last Edit: May 05, 2015, 12:38:03 PM by Peter »

Charles Pegge

  • Guest
Re: continuation Load&Save
« Reply #1 on: March 02, 2011, 01:07:41 PM »
Hi Peter,

Fixed the indirection problems

Code: [Select]

IndexBase 0
Declare Function ReadFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, ByRef lpNumberOfBytesRead As Long, ByRef lpOverlapped As OVERLAPPED) As Long
Declare Function WriteFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, ByRef lpNumberOfBytesWritten As Long, ByRef lpOverlapped As OVERLAPPED) As Long
Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Declare Function CreateFile  Lib "kernel32.dll" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Long sys_count

Function LoadFile(byval file as string,byval dest as long,byval count as long) as long
  Long  fHandle,dst
  dst = dest 
  push  0
  push  128
  push  4
  push  0
  push  1
  push  &h80000000
  push  file
  call  CreateFile
  mov   fHandle,eax
  Function = fHandle
  push  0
  lea   eax,sys_count
  push  eax
  push  count
  push  dest
  push  fHandle
  call  ReadFile
  push  fHandle
  call  CloseHandle
 End Function

Function SaveFile(byval file as string,byval dest as long,byval count as long) as long
  Long  fHandle
  push  0
  push  128
  push  4
  push  0   
  push  2
  push  &h40000000
  push  file
  call  CreateFile
  mov   fHandle,eax
  Function = fHandle
  push  0
  lea   eax,sys_count
  push  eax
  push  count
  push  dest
  push  fHandle
  call  WriteFile
  push  fHandle
  call  CloseHandle
  End Function

long x
string s1,s2,s3
Dim p(6) as byte
Dim m(6) as byte
For x=1 to 5
m(x) =x
next
s1 ="HELLO MAMA"
s2 ="          "
s3 ="          "

SaveFile "number.txt",&m,6
SaveFile "Mama.txt",*s1,Len(s1)

LoadFile "number.txt",&p,6
For x=1 To 5
print p(x)
next

LoadFile "Mama.txt",*s2,Len(s2)
print s2
LoadFile "Mama.txt",*s3,Len(s3)
print s3 + " HUHU"


Charles

Charles Pegge

  • Guest
Re: continuation Load&Save
« Reply #2 on: March 02, 2011, 09:11:08 PM »

Peter,

Yes that is a good way to pass a null pointer.
You can also force a BYREF parameter to take a null pointer by saying BYVAL 0.

Charles