Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Api.... lRead, lWrite....

Posted on 1997-06-25
2
Medium Priority
?
428 Views
Last Modified: 2012-06-21
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
  'Deallocate memory
 etc etc...

What am I doing wrong????
0
Comment
Question by:stephaner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
rmichels earned 120 total points
ID: 1427700
Try putting a ByVal in front of of mlng_MemoryAddress in the lwrite call.   I think VB is doing something weird, converting your memory address to a string before pass it on.  In my Win 3.1 code, that;s how I called lwrite
0
 

Author Comment

by:stephaner
ID: 1427701
This sis not work.  However, by changing the the function declaration from:
Private Declare Function lwrite Lib "kernel32" Alias "_lwrite" (ByVal hFile As Long, ByVal lpBuffer As string, ByVal wBytes As Long) As Long

to:
Private Declare Function lwrite Lib "kernel32" Alias "_lwrite" (ByVal hFile As Long, ByVal lpBuffer As Long, ByVal wBytes As Long) As Long

I have solved my problem
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question