CreateFile API 
Author Message
 CreateFile API

Hi,

    I'm trying to use the CreateFile API to get the handle to a device so i
can call DeviceIoContol API on the device and get more information for the
drive.  I am declaring the funtion in a module as follows

Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal
lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As
Long, lpSecurityAtributes As SECURITY_ATTRIBUTES, ByVal
dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal
hTemplateFile As Long) As Long

and calling it as follows

i = CreateFile(filename, 0, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0)

filename is a string variable containing a pathname and file
"c:\path\file.name"

This creates the file but the API returns  INVALID_HANDLE_VALUE instead of a
valid file handle.

any ideas ???

Thanks

Tony



Tue, 30 Oct 2001 03:00:00 GMT  
 CreateFile API
    Try this:

Public Declare Function CreateFile Lib "kernel32" _
    Alias "CreateFileA" _
    (ByVal lpFileName As String, _
     ByVal dwDesiredAccess As Long, _
     ByVal dwShareMode As Long, _
     lpSecurityAtributes As Any, _
     ByVal dwCreationDisposition As Long, _
     ByVal dwFlagsAndAttributes As Long, _
     ByVal hTemplateFile As Long) As Long

Public Const FILE_SHARE_READ = &H1
Public Const OPEN_ALWAYS = 4

    i = CreateFile(filename, _
                   0&, _
                   FILE_SHARE_READ, _
                   ByVal 0&, _
                   OPEN_ALWAYS, _
                   0&, _
                   0&)

--
Paul Parkhurst
Software Engineer

Quote:

>Hi,

>    I'm trying to use the CreateFile API to get the handle to a device so i
>can call DeviceIoContol API on the device and get more information for the
>drive.  I am declaring the funtion in a module as follows

>Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA"
(ByVal
>lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As
>Long, lpSecurityAtributes As SECURITY_ATTRIBUTES, ByVal
>dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal
>hTemplateFile As Long) As Long

>and calling it as follows

>i = CreateFile(filename, 0, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0)

>filename is a string variable containing a pathname and file
>"c:\path\file.name"

>This creates the file but the API returns  INVALID_HANDLE_VALUE instead of
a
>valid file handle.

>any ideas ???

>Thanks

>Tony



Wed, 31 Oct 2001 03:00:00 GMT  
 CreateFile API
If you are using windows 95, You can't get a file handle this way.  Search
the Knowledge base for Volume handles and it will point you to a method for
getting them in windows 95.

Wally

Quote:

>Hi,

>    I'm trying to use the CreateFile API to get the handle to a device so i
>can call DeviceIoContol API on the device and get more information for the
>drive.  I am declaring the funtion in a module as follows

>Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA"
(ByVal
>lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As
>Long, lpSecurityAtributes As SECURITY_ATTRIBUTES, ByVal
>dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal
>hTemplateFile As Long) As Long

>and calling it as follows

>i = CreateFile(filename, 0, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0)

>filename is a string variable containing a pathname and file
>"c:\path\file.name"

>This creates the file but the API returns  INVALID_HANDLE_VALUE instead of
a
>valid file handle.

>any ideas ???

>Thanks

>Tony



Wed, 31 Oct 2001 03:00:00 GMT  
 CreateFile API

Thanks Paul

    That worked great.  Got a successful call and a returned file handle :).
Now i have to work on getting the DeviceIoControl call to work successfully
to get the media type on the drive .  If you have any ideas about that i
would appreciate your thoughts.  Have a good weekend

Tony


Quote:
>     Try this:

> Public Declare Function CreateFile Lib "kernel32" _
>     Alias "CreateFileA" _
>     (ByVal lpFileName As String, _
>      ByVal dwDesiredAccess As Long, _
>      ByVal dwShareMode As Long, _
>      lpSecurityAtributes As Any, _
>      ByVal dwCreationDisposition As Long, _
>      ByVal dwFlagsAndAttributes As Long, _
>      ByVal hTemplateFile As Long) As Long

> Public Const FILE_SHARE_READ = &H1
> Public Const OPEN_ALWAYS = 4

>     i = CreateFile(filename, _
>                    0&, _
>                    FILE_SHARE_READ, _
>                    ByVal 0&, _
>                    OPEN_ALWAYS, _
>                    0&, _
>                    0&)

> --
> Paul Parkhurst
> Software Engineer


> >Hi,

> >    I'm trying to use the CreateFile API to get the handle to a device so
i
> >can call DeviceIoContol API on the device and get more information for
the
> >drive.  I am declaring the funtion in a module as follows

> >Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA"
> (ByVal
> >lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As
> >Long, lpSecurityAtributes As SECURITY_ATTRIBUTES, ByVal
> >dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal
> >hTemplateFile As Long) As Long

> >and calling it as follows

> >i = CreateFile(filename, 0, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0)

> >filename is a string variable containing a pathname and file
> >"c:\path\file.name"

> >This creates the file but the API returns  INVALID_HANDLE_VALUE instead
of
> a
> >valid file handle.

> >any ideas ???

> >Thanks

> >Tony



Wed, 31 Oct 2001 03:00:00 GMT  
 CreateFile API
    Check out the GetDriveType API.  It returns the media type of the path
you give it.

    Also, just in case you don't have them:

Type DIOC_REGISTERS
    reg_EBX As Long
    reg_EDX As Long
    reg_ECX As Long
    reg_EAX As Long
    reg_EDI As Long
    reg_ESI As Long
    reg_Flags As Long
End Type

Declare Function DeviceIoControl Lib "kernel32" _
    (ByVal hDevice As Long, _
     ByVal dwIoControlCode As Long, _
     lpInBuffer As Any, _
     ByVal nInBufferSize As Long, _
     lpOutBuffer As Any, _
     ByVal nOutBufferSize As Long, _
     lpBytesReturned As Long, _
     LPOVERLAPPED As Any) As Long

--
Paul Parkhurst
Software Engineer

Quote:

>Thanks Paul

>    That worked great.  Got a successful call and a returned file handle
:).
>Now i have to work on getting the DeviceIoControl call to work successfully
>to get the media type on the drive .  If you have any ideas about that i
>would appreciate your thoughts.  Have a good weekend

>Tony



>>     Try this:

>> Public Declare Function CreateFile Lib "kernel32" _
>>     Alias "CreateFileA" _
>>     (ByVal lpFileName As String, _
>>      ByVal dwDesiredAccess As Long, _
>>      ByVal dwShareMode As Long, _
>>      lpSecurityAtributes As Any, _
>>      ByVal dwCreationDisposition As Long, _
>>      ByVal dwFlagsAndAttributes As Long, _
>>      ByVal hTemplateFile As Long) As Long

>> Public Const FILE_SHARE_READ = &H1
>> Public Const OPEN_ALWAYS = 4

>>     i = CreateFile(filename, _
>>                    0&, _
>>                    FILE_SHARE_READ, _
>>                    ByVal 0&, _
>>                    OPEN_ALWAYS, _
>>                    0&, _
>>                    0&)

>> --
>> Paul Parkhurst
>> Software Engineer




- Show quoted text -

Quote:
>> >Hi,

>> >    I'm trying to use the CreateFile API to get the handle to a device
so
>i
>> >can call DeviceIoContol API on the device and get more information for
>the
>> >drive.  I am declaring the funtion in a module as follows

>> >Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA"
>> (ByVal
>> >lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode
As
>> >Long, lpSecurityAtributes As SECURITY_ATTRIBUTES, ByVal
>> >dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal
>> >hTemplateFile As Long) As Long

>> >and calling it as follows

>> >i = CreateFile(filename, 0, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0)

>> >filename is a string variable containing a pathname and file
>> >"c:\path\file.name"

>> >This creates the file but the API returns  INVALID_HANDLE_VALUE instead
>of
>> a
>> >valid file handle.

>> >any ideas ???

>> >Thanks

>> >Tony



Thu, 01 Nov 2001 03:00:00 GMT  
 CreateFile API
Paul,

    Yeah i had those, thanks :).  I have used the GetDriveType API to get a
general idea (i.e. local, cd-rom, removable).  I'm trying to use the
DeviceIoControl API to get more specific info on the Drive itself, like what
size disk it can take (i.e 3.5, 5.25)  DeviceIoControl can return the media
type....i just haven't been able to make a successful call to it so far....
I think it has to do with the control  code being passed and how it is
declared in the module..  I got the DeviceIoControl API declaration out of
the API text file but there is no reference to how to declare the constants
for the control code that needs to be passed, or for the structure that is
to be returned by  the call itself.  Still looking though....i tried to read
the winioctl.h file and translate the structures from there but i just got
confused reading it.  Thanks for all your help :)

Regards,

Tony

Quote:
>     Check out the GetDriveType API.  It returns the media type of the path
> you give it.

>     Also, just in case you don't have them:

> Type DIOC_REGISTERS
>     reg_EBX As Long
>     reg_EDX As Long
>     reg_ECX As Long
>     reg_EAX As Long
>     reg_EDI As Long
>     reg_ESI As Long
>     reg_Flags As Long
> End Type

> Declare Function DeviceIoControl Lib "kernel32" _
>     (ByVal hDevice As Long, _
>      ByVal dwIoControlCode As Long, _
>      lpInBuffer As Any, _
>      ByVal nInBufferSize As Long, _
>      lpOutBuffer As Any, _
>      ByVal nOutBufferSize As Long, _
>      lpBytesReturned As Long, _
>      LPOVERLAPPED As Any) As Long

> --
> Paul Parkhurst
> Software Engineer


> >Thanks Paul

> >    That worked great.  Got a successful call and a returned file handle
> :).
> >Now i have to work on getting the DeviceIoControl call to work
successfully
> >to get the media type on the drive .  If you have any ideas about that i
> >would appreciate your thoughts.  Have a good weekend

> >Tony



> >>     Try this:

> >> Public Declare Function CreateFile Lib "kernel32" _
> >>     Alias "CreateFileA" _
> >>     (ByVal lpFileName As String, _
> >>      ByVal dwDesiredAccess As Long, _
> >>      ByVal dwShareMode As Long, _
> >>      lpSecurityAtributes As Any, _
> >>      ByVal dwCreationDisposition As Long, _
> >>      ByVal dwFlagsAndAttributes As Long, _
> >>      ByVal hTemplateFile As Long) As Long

> >> Public Const FILE_SHARE_READ = &H1
> >> Public Const OPEN_ALWAYS = 4

> >>     i = CreateFile(filename, _
> >>                    0&, _
> >>                    FILE_SHARE_READ, _
> >>                    ByVal 0&, _
> >>                    OPEN_ALWAYS, _
> >>                    0&, _
> >>                    0&)

> >> --
> >> Paul Parkhurst
> >> Software Engineer



> >> >Hi,

> >> >    I'm trying to use the CreateFile API to get the handle to a device
> so
> >i
> >> >can call DeviceIoContol API on the device and get more information for
> >the
> >> >drive.  I am declaring the funtion in a module as follows

> >> >Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA"
> >> (ByVal
> >> >lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode
> As
> >> >Long, lpSecurityAtributes As SECURITY_ATTRIBUTES, ByVal
> >> >dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long,
ByVal
> >> >hTemplateFile As Long) As Long

> >> >and calling it as follows

> >> >i = CreateFile(filename, 0, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0)

> >> >filename is a string variable containing a pathname and file
> >> >"c:\path\file.name"

> >> >This creates the file but the API returns  INVALID_HANDLE_VALUE
instead
> >of
> >> a
> >> >valid file handle.

> >> >any ideas ???

> >> >Thanks

> >> >Tony



Thu, 01 Nov 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. CreateFile - API, Am I a Pudding?

2. CreateFile API

3. CreateFile API call with VB4(32) on Win95 OS

4. Createfile API problem with COM ports

5. CreateFile API or MSComm

6. CreateFile API or MSComm

7. Createfile API

8. CreateFile API Return INVALID_HANDLE_VALUE

9. createfile api call

10. CreateFile API Return INVALID_HANDLE_VALUE

11. CreateFile API Help

12. CreateFile API Help

 

 
Powered by phpBB® Forum Software