CreateFile API call with VB4(32) on Win95 OS 
Author Message
 CreateFile API call with VB4(32) on Win95 OS

Hi all,

        Anybody would know why the folowing code fails to either create a new
file or reopen an existing one. The fHandl value is always = -1 and the
GetLastError always return 0. I have: consulted the SDK, MSKB, DejaNews for
old articles, VB4 documentation and also tempered with all the constants and
settings for three days non-stop now. I am in the process of loosing: my hair,
some weight and my wife. If you've got any hint...

___________________________________________________________________
'* Means on one line *'
Option Explicit 'In Form's declaration

'For opening the file
Const FILE_SHARE_READ = &H1
Const FILE_ATTRIBUTE_NORMAL = &H80
Const FILE_FLAG_RANDOM_ACCESS = &H10000000
Const GENERIC_READ = &H80000000
Const OPEN_ALWAYS = 4
Private Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Boolean
End Type
'*
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal
lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As
Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition
As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As
Long
*'
'For reading the file
Private Type OVERLAPPED
        Internal As Long
        InternalHigh As Long
        offset As Long
        OffsetHigh As Long
        hEvent As Long
End Type
'*
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long,
lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As
Long, lpOverlapped As OVERLAPPED) As Long
*'
'For closing the file
'*
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As
Long
*'
'for getting the error code
Private Declare Function GetLastError Lib "kernel32" () As Long

Private Sub Command1_Click()
        Dim MYSECURITY_ATTRIBUTES As SECURITY_ATTRIBUTES
        Dim MYOVERLAPPED As OVERLAPPED
        Dim fHandl As Long
        Dim r As Long
        Dim ReadBytes As String * 200
        Dim ReturnedNumberBytes As Long
        Dim c As Long
        Dim LastError As Long

        MYSECURITY_ATTRIBUTES.nLength = 10
        MYSECURITY_ATTRIBUTES.lpSecurityDescriptor = 0
        MYSECURITY_ATTRIBUTES.bInheritHandle = True

        MYOVERLAPPED.Internal = 0
        MYOVERLAPPED.InternalHigh = 0
        MYOVERLAPPED.offset = 0
        MYOVERLAPPED.OffsetHigh = 0
        MYOVERLAPPED.hEvent = 0

'Next statement never seems to return another value then -1
'*
        fHandl = CreateFile("c:\test2.blr", GENERIC_READ, FILE_SHARE_READ,
MYSECURITY_ATTRIBUTES, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL +
FILE_FLAG_RANDOM_ACCESS, 0)
*'  
'LastError always = 0
      LastError = GetLastError
'*
        r = ReadFile(fHandl, ReadBytes, 200, ReturnedNumberBytes,
MYOVERLAPPED)
*'  
      c = CloseHandle(fHandl)
End Sub
___________________________________________________________________

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    
"You might know a Sylvain C?t, but it is not me"
                                - Sylvain C?t                        
Sylvain C?t

McGill University
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Wed, 21 Jul 1999 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Please help with CreateProcess API call (VB4-32)

2. VB4.0 32/16 APIs call.... HELP

3. VB4.0/32: GetTempFileName API Call - How to ?

4. Calling 32-bit DLL function from 32-bit VB4 app

5. ExtractIconEx API call (VB4/Win95)

6. HELP -- VB4-32 bit appl,Win95, and WinNT

7. Running Multiple VB4 32-bit Exes under Win95

8. HELP....CREATING CUSTOM OPEN DIALOG/WIN95 IN VB4 32-BIT

9. VB Made SSaver automatically previewed when selected in Display properties in Win95 [VB4/32]

10. Help error #5 on Form minimize VB4.0 32 Win95

11. HELP -- VB4-32 bit appl,Win95, and WinNT

12. Running Vb3, Vb4 16 & 32 on Win95

 

 
Powered by phpBB® Forum Software