From: Lorin on
VB6SP6
I am using the API to open a file to read.
It works properly on 99.9% of the files I use it on.
Once in a while I run into a file that it will not open for reading.
The file atributes are only Archive.
Other files in the same folder are opened and read without problems with the
same subroutine.
No other application has the file open.
The Open fails with INVALID_HANDLE_VALUE.
What is so unique about this file?
The current file is a PDF that I created using Adobe PDF Writer.
How do I accomplish the open?
I can, without problems, use Windows Explorer to copy and paste the file.

If fails on the Open atttempt:
Private Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" (ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long

m_hFile = CreateFile(sFileName, eAccessMode, eShareMode, eSecurity,
eDisposition, eAttribute, 0)

eAccessMode = GENERIC_READ
eShareMode = 0
eSecurity = 0
eDisposition = OPEN_EXISTING
eAttribute = 128 ' Normal

Suggestions please.


From: Lorin on
IF I try my FileExists routine it says the file is not there.
Yet W.E. lets me see it, copy it etc.
There must be some API that I can call to allow me access to this file.

Public Function FileExists(sSource As String) As Boolean

On Error GoTo FileExistsErr

Dim WFD As WIN32_FIND_DATA
Dim hFile As Long

hFile = FindFirstFile(sSource, WFD)
FileExists = hFile <> INVALID_HANDLE_VALUE

FileExistsExit:
' release
On Error Resume Next
Call FindClose(hFile)
Exit Function

FileExistsErr:
Resume FileExistsExit

End Function 'FileExists


"Lorin" wrote:

> VB6SP6
> I am using the API to open a file to read.
> It works properly on 99.9% of the files I use it on.
> Once in a while I run into a file that it will not open for reading.
> The file atributes are only Archive.
> Other files in the same folder are opened and read without problems with the
> same subroutine.
> No other application has the file open.
> The Open fails with INVALID_HANDLE_VALUE.
> What is so unique about this file?
> The current file is a PDF that I created using Adobe PDF Writer.
> How do I accomplish the open?
> I can, without problems, use Windows Explorer to copy and paste the file.
>
> If fails on the Open atttempt:
> Private Declare Function CreateFile Lib "kernel32" _
> Alias "CreateFileA" (ByVal lpFileName As String, _
> ByVal dwDesiredAccess As Long, _
> ByVal dwShareMode As Long, _
> ByVal lpSecurityAttributes As Long, _
> ByVal dwCreationDisposition As Long, _
> ByVal dwFlagsAndAttributes As Long, _
> ByVal hTemplateFile As Long) As Long
>
> m_hFile = CreateFile(sFileName, eAccessMode, eShareMode, eSecurity,
> eDisposition, eAttribute, 0)
>
> eAccessMode = GENERIC_READ
> eShareMode = 0
> eSecurity = 0
> eDisposition = OPEN_EXISTING
> eAttribute = 128 ' Normal
>
> Suggestions please.
>
>