VB-5 on Win NT
Hello. I am having a problem using these API functions.
The problem is that I can use lRead to read a file into memory. However when I try to write the data back into a file something is going wrong.
What is happening is that the file is created however, the
file contains the address of the pointer I am using followed buy garbage.
Here is a sniplet of the code to read the file into memory
mlng_MemoryHandle = GlobalAlloc(GMEM_ZEROINIT, FileSize)
mlng_MemoryAddress = GlobalLock(mlng_MemoryHandle)
hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, ByVal 0&, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, ByVal 0&)
retval = lread(hFile, ByVal mlng_MemoryAddress, FileSize)
retval = CloseHandle(hFile)
Up until here everthing is fine. the problem must be here.
hFile = CreateFile(FileName, GENERIC_WRITE, FILE_SHARE_WRITE, ByVal 0&, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, ByVal 0&)
MemSize = GlobalSize(mlng_MemoryHandle)
retval = lwrite(hFile, mlng_MemoryAddress, MemSize)
'Close the File
'Unlock Allocated memory
What am I doing wrong????