Solved

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

Posted on 1997-06-25
2
425 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 40 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

615 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