Retrieving and Passing Pointers 
Author Message
 Retrieving and Passing Pointers

I would like to take a pointer from the first lread function and then pass
it to the second lwrite function but I am having all sorts of problems .
Starting with the declarations

                                lread lngSrcFileNum, ******, BytesPerCopy
                                lwrite lngDestFileNum, ******, BytesPerCopy

Any help appreciated

Alex



Fri, 10 Aug 2001 03:00:00 GMT  
 Retrieving and Passing Pointers
Try something like the following (add your own cleanup and error handling).
Some people will use strings for the buffers instead of a byte array, but
this will cause data munging in cross-CP scenarios:

' a few Win32 API constants
Global Const INVALID_HANDLE_VALUE = -1
Global Const GENERIC_READ = &H80000000
Global Const GENERIC_WRITE = &H40000000
Global Const FILE_ATTRIBUTE_NORMAL = &H80
Global Const CREATE_ALWAYS = 2
Global Const OPEN_EXISTING = 3
Global Const FILE_SHARE_READ = &H1
Global Const FILE_SHARE_WRITE = &H2

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long)
As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA"
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal
dwShareMode As Long, lpSecurityAttributes As Any, ByVal
dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal
hTemplateFile As Long) As Long
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA"
(ByVal lpFileName As String) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long,
lpBuffer As Byte, ByVal nNumberOfBytesToRead As Long, ByRef
lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long,
lpBuffer As Byte, ByVal nNumberOfBytesToWrite As Long, ByRef
lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long

'------------------------------------------------------------
'   FCopyFile
'
'   Copies a file.  This is much better than the VBA
'   FileCopy, which will not let you copy a file with
'   any sort of file lock on it.
'------------------------------------------------------------
Function FCopyFile(stSrc As String, stDest As String) As Boolean

    Dim hFileSrc As Long
    Dim hFileDest As Long
    Dim dwBytesRead As Long
    Dim dwBytesWritten As Long
    Dim buffer() As Byte

    ' Open the existing file.
    hFileSrc = CreateFile(stSrc, GENERIC_READ, FILE_SHARE_READ Or
FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, ByVal 0&)

    If (hFileSrc <> INVALID_HANDLE_VALUE) Then

        hFileDest = CreateFile(stDest, GENERIC_READ Or GENERIC_WRITE, 0,
ByVal 0&, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, ByVal 0&)

        If (hFileDest <> INVALID_HANDLE_VALUE) Then

            ' Read 4K blocks to the buffer and write them
            Do
                ReDim buffer(4096)
                If (ReadFile(hFileSrc, buffer(0), 4096, dwBytesRead, ByVal
0&)) Then
                    Call WriteFile(hFileDest, buffer(0), dwBytesRead,
dwBytesWritten, ByVal 0&)
                End If
            Loop While (dwBytesRead = 4096)

            Call CloseHandle(hFileDest)
            FCopyFile = True
        End If

        Call CloseHandle(hFileSrc)

    End If

End Function



Quote:
> I would like to take a pointer from the first lread function and then pass
> it to the second lwrite function but I am having all sorts of problems .
> Starting with the declarations

>                                 lread lngSrcFileNum, ******, BytesPerCopy
>                                 lwrite lngDestFileNum, ******,
BytesPerCopy

> Any help appreciated

> Alex



Fri, 10 Aug 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing pointer to a pointer or pointer to a char to a dll

2. how to pass a pointer to a pointer in a dll

3. Passing pointer to pointer to C struct from VB into a DLL

4. Passing pointer to pointer to a structure to a WINAPI function

5. How to retrieve a structure from a pointer

6. Can't I retrieve an interface pointer inside VB Script

7. How to use pointer and the pointer of pointedness pointer in vb

8. How to use pointer and the pointer of pointedness pointer in vb

9. How to use pointer and the pointer of pointedness pointer in vb

10. How to use pointer and the pointer of pointedness pointer in vb

11. How to use pointer and the pointer of pointedness pointer in vb

12. Passing Arrays Pointer To API

 

 
Powered by phpBB® Forum Software