Home All Groups Group Topic Archive Search About

Translation of CreateFile dll in dot net

Author
29 Mar 2006 10:09 AM
news.microsoft.com
Hello,

i'm having problems to call a api dll in vb dot net.
I absolutely want to use this api call and none of the frame calls.

This is my declaration:
*****************
Public Structure SECURITY_ATTRIBUTES
    Public nLength As UInt32
    Public lpSecurityDescriptor As IntPtr
    Public bInheritHandle As Int32
End Structure

' Desired Access
Public Const FILE_READ_DATA = 1
Public Const FILE_WRITE_DATA = 2
Public Const FILE_APPEND_DATA = 4

' ShareMode
Public Const FILE_SHARE_READ = &H1
Public Const FILE_SHARE_WRITE = &H2

' CreationDisposition
Public Const CREATE_NEW = 1
Public Const OPEN_EXISTING = 3

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


This is the call:
***********

Dim lFile As Long = LibWrap.CreateFile("c:\test\myfile.dat",
LibWrap.FILE_READ_DATA, LibWrap.FILE_SHARE_READ, Nothing,
LibWrap.OPEN_EXISTING, 0, Nothing)


Anyone an idea?
This is my first api call.

Grtz.

Author
29 Mar 2006 12:33 PM
Al Reid
You need to be aware of data type mapping between .Net and the API calls and also be aware that if you are using declarations from
VB5/6 that a VB5/6 Long maps to a VB.Net Integer.

Without looking in any detail, first try changing all Long to Integer in the CreateFile declaration.

--
Al Reid

Show quoteHide quote
"news.microsoft.com" <Yves_no_spam@hotmail.com> wrote in message news:u8gnbjxUGHA.2276@tk2msftngp13.phx.gbl...
> Hello,
>
> i'm having problems to call a api dll in vb dot net.
> I absolutely want to use this api call and none of the frame calls.
>
> This is my declaration:
> *****************
> Public Structure SECURITY_ATTRIBUTES
>     Public nLength As UInt32
>     Public lpSecurityDescriptor As IntPtr
>     Public bInheritHandle As Int32
> End Structure
>
> ' Desired Access
> Public Const FILE_READ_DATA = 1
> Public Const FILE_WRITE_DATA = 2
> Public Const FILE_APPEND_DATA = 4
>
> ' ShareMode
> Public Const FILE_SHARE_READ = &H1
> Public Const FILE_SHARE_WRITE = &H2
>
> ' CreationDisposition
> Public Const CREATE_NEW = 1
> Public Const OPEN_EXISTING = 3
>
> Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
>    (ByVal lpFileName As String, _
>     ByVal dwDesiredAccess As Long, _
>     ByVal dwShareMode As Long, _
>     ByVal lpSecurityAttributes As SECURITY_ATTRIBUTES, _
>     ByVal dwCreationDisposition As Long, _
>     ByVal dwFlagsAndAttributes As Long, _
>     ByVal hTemplateFile As IntPtr) _
> As Long
>
>
> This is the call:
> ***********
>
> Dim lFile As Long = LibWrap.CreateFile("c:\test\myfile.dat",
> LibWrap.FILE_READ_DATA, LibWrap.FILE_SHARE_READ, Nothing,
> LibWrap.OPEN_EXISTING, 0, Nothing)
>
>
> Anyone an idea?
> This is my first api call.
>
> Grtz.
>
>
Author
29 Mar 2006 12:57 PM
news.microsoft.com
I've changed the code with no luck:

Declaration:
*********
Const FILE_READ_DATA = 1
Const OPEN_EXISTING = 3
Const FILE_SHARE_READ = &H1
Const FILE_SHARE_WRITE = &H2
Const FILE_ATTRIBUTE_NORMAL = &H80

<StructLayout(LayoutKind.Sequential)> _
Structure SECURITY_ATTRIBUTES
    Public nLength As Int32
    Public lpSecurityDescriptor As IntPtr
    Public bInheritHandle As Boolean
End Structure

Declare Auto Function CreateFile Lib "kernel32" ( _
    ByVal lpFileName As String, _
    ByVal dwDesiredAccess As Int32, _
    ByVal dwShareMode As Int32, _
    ByRef lpSecurityAttributes As IntPtr, _
    ByVal dwCreationDistribution As Int32, _
    ByVal dwFlagsAndAttributes As Int32, _
    ByVal hTemplateFile As IntPtr _
) As IntPtr

Call:
****
Dim fh As IntPtr

fh = CreateFile("c:\test\test.txt", FILE_READ_DATA, FILE_SHARE_READ,
IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)

If fh.ToInt32 = -1 Then
   MessageBox.Show("Invalid")
End If


I don't see what's wrong ...

"Al Reid" <arei***@reidDASHhome.com> wrote in message
news:%232iFK0yUGHA.5652@TK2MSFTNGP09.phx.gbl...
> You need to be aware of data type mapping between .Net and the API calls
and also be aware that if you are using declarations from
> VB5/6 that a VB5/6 Long maps to a VB.Net Integer.
>
> Without looking in any detail, first try changing all Long to Integer in
the CreateFile declaration.
Show quoteHide quote
>
> --
> Al Reid
>
> "news.microsoft.com" <Yves_no_spam@hotmail.com> wrote in message
news:u8gnbjxUGHA.2276@tk2msftngp13.phx.gbl...
> > Hello,
> >
> > i'm having problems to call a api dll in vb dot net.
> > I absolutely want to use this api call and none of the frame calls.
> >
> > This is my declaration:
> > *****************
> > Public Structure SECURITY_ATTRIBUTES
> >     Public nLength As UInt32
> >     Public lpSecurityDescriptor As IntPtr
> >     Public bInheritHandle As Int32
> > End Structure
> >
> > ' Desired Access
> > Public Const FILE_READ_DATA = 1
> > Public Const FILE_WRITE_DATA = 2
> > Public Const FILE_APPEND_DATA = 4
> >
> > ' ShareMode
> > Public Const FILE_SHARE_READ = &H1
> > Public Const FILE_SHARE_WRITE = &H2
> >
> > ' CreationDisposition
> > Public Const CREATE_NEW = 1
> > Public Const OPEN_EXISTING = 3
> >
> > Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
> >    (ByVal lpFileName As String, _
> >     ByVal dwDesiredAccess As Long, _
> >     ByVal dwShareMode As Long, _
> >     ByVal lpSecurityAttributes As SECURITY_ATTRIBUTES, _
> >     ByVal dwCreationDisposition As Long, _
> >     ByVal dwFlagsAndAttributes As Long, _
> >     ByVal hTemplateFile As IntPtr) _
> > As Long
> >
> >
> > This is the call:
> > ***********
> >
> > Dim lFile As Long = LibWrap.CreateFile("c:\test\myfile.dat",
> > LibWrap.FILE_READ_DATA, LibWrap.FILE_SHARE_READ, Nothing,
> > LibWrap.OPEN_EXISTING, 0, Nothing)
> >
> >
> > Anyone an idea?
> > This is my first api call.
> >
> > Grtz.
> >
> >
>
>
Author
29 Mar 2006 1:12 PM
Al Reid
That's because you changed the Longs to Int32, which was no change at all.  You need to use either Integer or Int16.  A DWORD is two
(2) 8 bit words or a 16-bit integer.

--
Al Reid

Show quoteHide quote
"news.microsoft.com" <Yves_no_spam@hotmail.com> wrote in message news:eCuZkBzUGHA.5900@tk2msftngp13.phx.gbl...
> I've changed the code with no luck:
>
> Declaration:
> *********
> Const FILE_READ_DATA = 1
> Const OPEN_EXISTING = 3
> Const FILE_SHARE_READ = &H1
> Const FILE_SHARE_WRITE = &H2
> Const FILE_ATTRIBUTE_NORMAL = &H80
>
> <StructLayout(LayoutKind.Sequential)> _
> Structure SECURITY_ATTRIBUTES
>     Public nLength As Int32
>     Public lpSecurityDescriptor As IntPtr
>     Public bInheritHandle As Boolean
> End Structure
>
> Declare Auto Function CreateFile Lib "kernel32" ( _
>     ByVal lpFileName As String, _
>     ByVal dwDesiredAccess As Int32, _
>     ByVal dwShareMode As Int32, _
>     ByRef lpSecurityAttributes As IntPtr, _
>     ByVal dwCreationDistribution As Int32, _
>     ByVal dwFlagsAndAttributes As Int32, _
>     ByVal hTemplateFile As IntPtr _
> ) As IntPtr
>
> Call:
> ****
> Dim fh As IntPtr
>
> fh = CreateFile("c:\test\test.txt", FILE_READ_DATA, FILE_SHARE_READ,
> IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)
>
> If fh.ToInt32 = -1 Then
>    MessageBox.Show("Invalid")
> End If
>
>
> I don't see what's wrong ...
>
> "Al Reid" <arei***@reidDASHhome.com> wrote in message
> news:%232iFK0yUGHA.5652@TK2MSFTNGP09.phx.gbl...
> > You need to be aware of data type mapping between .Net and the API calls
> and also be aware that if you are using declarations from
> > VB5/6 that a VB5/6 Long maps to a VB.Net Integer.
> >
> > Without looking in any detail, first try changing all Long to Integer in
> the CreateFile declaration.
> >
> > --
> > Al Reid
> >
> > "news.microsoft.com" <Yves_no_spam@hotmail.com> wrote in message
> news:u8gnbjxUGHA.2276@tk2msftngp13.phx.gbl...
> > > Hello,
> > >
> > > i'm having problems to call a api dll in vb dot net.
> > > I absolutely want to use this api call and none of the frame calls.
> > >
> > > This is my declaration:
> > > *****************
> > > Public Structure SECURITY_ATTRIBUTES
> > >     Public nLength As UInt32
> > >     Public lpSecurityDescriptor As IntPtr
> > >     Public bInheritHandle As Int32
> > > End Structure
> > >
> > > ' Desired Access
> > > Public Const FILE_READ_DATA = 1
> > > Public Const FILE_WRITE_DATA = 2
> > > Public Const FILE_APPEND_DATA = 4
> > >
> > > ' ShareMode
> > > Public Const FILE_SHARE_READ = &H1
> > > Public Const FILE_SHARE_WRITE = &H2
> > >
> > > ' CreationDisposition
> > > Public Const CREATE_NEW = 1
> > > Public Const OPEN_EXISTING = 3
> > >
> > > Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
> > >    (ByVal lpFileName As String, _
> > >     ByVal dwDesiredAccess As Long, _
> > >     ByVal dwShareMode As Long, _
> > >     ByVal lpSecurityAttributes As SECURITY_ATTRIBUTES, _
> > >     ByVal dwCreationDisposition As Long, _
> > >     ByVal dwFlagsAndAttributes As Long, _
> > >     ByVal hTemplateFile As IntPtr) _
> > > As Long
> > >
> > >
> > > This is the call:
> > > ***********
> > >
> > > Dim lFile As Long = LibWrap.CreateFile("c:\test\myfile.dat",
> > > LibWrap.FILE_READ_DATA, LibWrap.FILE_SHARE_READ, Nothing,
> > > LibWrap.OPEN_EXISTING, 0, Nothing)
> > >
> > >
> > > Anyone an idea?
> > > This is my first api call.
> > >
> > > Grtz.
> > >
> > >
> >
> >
>
>
Author
29 Mar 2006 1:31 PM
news.microsoft.com
I tried it but that doesn't work either.
thanks.

"Al Reid" <arei***@reidDASHhome.com> wrote in message
news:%23aWLuJzUGHA.5996@TK2MSFTNGP10.phx.gbl...
> That's because you changed the Longs to Int32, which was no change at all.
You need to use either Integer or Int16.  A DWORD is two
Show quoteHide quote
> (2) 8 bit words or a 16-bit integer.
>
> --
> Al Reid
>
> "news.microsoft.com" <Yves_no_spam@hotmail.com> wrote in message
news:eCuZkBzUGHA.5900@tk2msftngp13.phx.gbl...
> > I've changed the code with no luck:
> >
> > Declaration:
> > *********
> > Const FILE_READ_DATA = 1
> > Const OPEN_EXISTING = 3
> > Const FILE_SHARE_READ = &H1
> > Const FILE_SHARE_WRITE = &H2
> > Const FILE_ATTRIBUTE_NORMAL = &H80
> >
> > <StructLayout(LayoutKind.Sequential)> _
> > Structure SECURITY_ATTRIBUTES
> >     Public nLength As Int32
> >     Public lpSecurityDescriptor As IntPtr
> >     Public bInheritHandle As Boolean
> > End Structure
> >
> > Declare Auto Function CreateFile Lib "kernel32" ( _
> >     ByVal lpFileName As String, _
> >     ByVal dwDesiredAccess As Int32, _
> >     ByVal dwShareMode As Int32, _
> >     ByRef lpSecurityAttributes As IntPtr, _
> >     ByVal dwCreationDistribution As Int32, _
> >     ByVal dwFlagsAndAttributes As Int32, _
> >     ByVal hTemplateFile As IntPtr _
> > ) As IntPtr
> >
> > Call:
> > ****
> > Dim fh As IntPtr
> >
> > fh = CreateFile("c:\test\test.txt", FILE_READ_DATA, FILE_SHARE_READ,
> > IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)
> >
> > If fh.ToInt32 = -1 Then
> >    MessageBox.Show("Invalid")
> > End If
> >
> >
> > I don't see what's wrong ...
> >
> > "Al Reid" <arei***@reidDASHhome.com> wrote in message
> > news:%232iFK0yUGHA.5652@TK2MSFTNGP09.phx.gbl...
> > > You need to be aware of data type mapping between .Net and the API
calls
> > and also be aware that if you are using declarations from
> > > VB5/6 that a VB5/6 Long maps to a VB.Net Integer.
> > >
> > > Without looking in any detail, first try changing all Long to Integer
in
> > the CreateFile declaration.
> > >
> > > --
> > > Al Reid
> > >
> > > "news.microsoft.com" <Yves_no_spam@hotmail.com> wrote in message
> > news:u8gnbjxUGHA.2276@tk2msftngp13.phx.gbl...
> > > > Hello,
> > > >
> > > > i'm having problems to call a api dll in vb dot net.
> > > > I absolutely want to use this api call and none of the frame calls.
> > > >
> > > > This is my declaration:
> > > > *****************
> > > > Public Structure SECURITY_ATTRIBUTES
> > > >     Public nLength As UInt32
> > > >     Public lpSecurityDescriptor As IntPtr
> > > >     Public bInheritHandle As Int32
> > > > End Structure
> > > >
> > > > ' Desired Access
> > > > Public Const FILE_READ_DATA = 1
> > > > Public Const FILE_WRITE_DATA = 2
> > > > Public Const FILE_APPEND_DATA = 4
> > > >
> > > > ' ShareMode
> > > > Public Const FILE_SHARE_READ = &H1
> > > > Public Const FILE_SHARE_WRITE = &H2
> > > >
> > > > ' CreationDisposition
> > > > Public Const CREATE_NEW = 1
> > > > Public Const OPEN_EXISTING = 3
> > > >
> > > > Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
> > > >    (ByVal lpFileName As String, _
> > > >     ByVal dwDesiredAccess As Long, _
> > > >     ByVal dwShareMode As Long, _
> > > >     ByVal lpSecurityAttributes As SECURITY_ATTRIBUTES, _
> > > >     ByVal dwCreationDisposition As Long, _
> > > >     ByVal dwFlagsAndAttributes As Long, _
> > > >     ByVal hTemplateFile As IntPtr) _
> > > > As Long
> > > >
> > > >
> > > > This is the call:
> > > > ***********
> > > >
> > > > Dim lFile As Long = LibWrap.CreateFile("c:\test\myfile.dat",
> > > > LibWrap.FILE_READ_DATA, LibWrap.FILE_SHARE_READ, Nothing,
> > > > LibWrap.OPEN_EXISTING, 0, Nothing)
> > > >
> > > >
> > > > Anyone an idea?
> > > > This is my first api call.
> > > >
> > > > Grtz.
> > > >
> > > >
> > >
> > >
> >
> >
>
>
Author
29 Mar 2006 1:53 PM
Claes Bergefall
See inline

"Al Reid" <arei***@reidDASHhome.com> wrote in message
news:%23aWLuJzUGHA.5996@TK2MSFTNGP10.phx.gbl...
> That's because you changed the Longs to Int32, which was no change at all.
> You need to use either Integer or Int16.  A DWORD is two
> (2) 8 bit words or a 16-bit integer.
>

Ehh, no. A DWORD is 32 bits, same as Long in VB6 and Int32/Integer in VB.NET


Show quoteHide quote
> --
> Al Reid
>
> "news.microsoft.com" <Yves_no_spam@hotmail.com> wrote in message
> news:eCuZkBzUGHA.5900@tk2msftngp13.phx.gbl...
>> I've changed the code with no luck:
>>
>> Declaration:
>> *********
>> Const FILE_READ_DATA = 1
>> Const OPEN_EXISTING = 3
>> Const FILE_SHARE_READ = &H1
>> Const FILE_SHARE_WRITE = &H2
>> Const FILE_ATTRIBUTE_NORMAL = &H80
>>
>> <StructLayout(LayoutKind.Sequential)> _
>> Structure SECURITY_ATTRIBUTES
>>     Public nLength As Int32
>>     Public lpSecurityDescriptor As IntPtr
>>     Public bInheritHandle As Boolean
>> End Structure
>>
>> Declare Auto Function CreateFile Lib "kernel32" ( _
>>     ByVal lpFileName As String, _
>>     ByVal dwDesiredAccess As Int32, _
>>     ByVal dwShareMode As Int32, _
>>     ByRef lpSecurityAttributes As IntPtr, _
>>     ByVal dwCreationDistribution As Int32, _
>>     ByVal dwFlagsAndAttributes As Int32, _
>>     ByVal hTemplateFile As IntPtr _
>> ) As IntPtr
>>
>> Call:
>> ****
>> Dim fh As IntPtr
>>
>> fh = CreateFile("c:\test\test.txt", FILE_READ_DATA, FILE_SHARE_READ,
>> IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)
>>
>> If fh.ToInt32 = -1 Then
>>    MessageBox.Show("Invalid")
>> End If
>>
>>
>> I don't see what's wrong ...
>>

Try this:

Const FILE_READ_DATA As Int32 = 1
Const OPEN_EXISTING As Int32 = 3
Const FILE_SHARE_READ As Int32 = &H1
Const FILE_SHARE_WRITE As Int32 = &H2
Const FILE_ATTRIBUTE_NORMAL As Int32 = &H80

<StructLayout(LayoutKind.Sequential)> _
Structure SECURITY_ATTRIBUTES
    Public nLength As Int32
    Public lpSecurityDescriptor As IntPtr
    Public bInheritHandle As Boolean
End Structure

Declare Auto Function CreateFile Lib "kernel32" ( _
    <MarshalAs(UnmanagedType.LPTStr)> ByVal lpFileName As String, _
    ByVal dwDesiredAccess As Int32, _
    ByVal dwShareMode As Int32, _
    ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, _
    ByVal dwCreationDistribution As Int32, _
    ByVal dwFlagsAndAttributes As Int32, _
    ByVal hTemplateFile As IntPtr _
) As IntPtr

If this doesn't work try changing the lpSecurityAttributes parameter to
ByVal instead of ByRef

    /claes
Author
29 Mar 2006 2:05 PM
Al Reid
Sorry, ehh, you're right.  My bad.  Anyhow, when converting VB5/6 Declarations, the VB5/6 Long converts to a VB.Net Integer.

Also the SECURITY_ATTRIBUTES structure needs to be adjusted as well.

--
Al Reid

Show quoteHide quote
"Claes Bergefall" <claes.bergefall@nospam.nospam> wrote in message news:emIHlfzUGHA.2704@tk2msftngp13.phx.gbl...
> See inline
>
> "Al Reid" <arei***@reidDASHhome.com> wrote in message
> news:%23aWLuJzUGHA.5996@TK2MSFTNGP10.phx.gbl...
> > That's because you changed the Longs to Int32, which was no change at all.
> > You need to use either Integer or Int16.  A DWORD is two
> > (2) 8 bit words or a 16-bit integer.
> >
>
> Ehh, no. A DWORD is 32 bits, same as Long in VB6 and Int32/Integer in VB.NET
>
>
> > --
> > Al Reid
> >
> > "news.microsoft.com" <Yves_no_spam@hotmail.com> wrote in message
> > news:eCuZkBzUGHA.5900@tk2msftngp13.phx.gbl...
> >> I've changed the code with no luck:
> >>
> >> Declaration:
> >> *********
> >> Const FILE_READ_DATA = 1
> >> Const OPEN_EXISTING = 3
> >> Const FILE_SHARE_READ = &H1
> >> Const FILE_SHARE_WRITE = &H2
> >> Const FILE_ATTRIBUTE_NORMAL = &H80
> >>
> >> <StructLayout(LayoutKind.Sequential)> _
> >> Structure SECURITY_ATTRIBUTES
> >>     Public nLength As Int32
> >>     Public lpSecurityDescriptor As IntPtr
> >>     Public bInheritHandle As Boolean
> >> End Structure
> >>
> >> Declare Auto Function CreateFile Lib "kernel32" ( _
> >>     ByVal lpFileName As String, _
> >>     ByVal dwDesiredAccess As Int32, _
> >>     ByVal dwShareMode As Int32, _
> >>     ByRef lpSecurityAttributes As IntPtr, _
> >>     ByVal dwCreationDistribution As Int32, _
> >>     ByVal dwFlagsAndAttributes As Int32, _
> >>     ByVal hTemplateFile As IntPtr _
> >> ) As IntPtr
> >>
> >> Call:
> >> ****
> >> Dim fh As IntPtr
> >>
> >> fh = CreateFile("c:\test\test.txt", FILE_READ_DATA, FILE_SHARE_READ,
> >> IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)
> >>
> >> If fh.ToInt32 = -1 Then
> >>    MessageBox.Show("Invalid")
> >> End If
> >>
> >>
> >> I don't see what's wrong ...
> >>
>
> Try this:
>
> Const FILE_READ_DATA As Int32 = 1
> Const OPEN_EXISTING As Int32 = 3
> Const FILE_SHARE_READ As Int32 = &H1
> Const FILE_SHARE_WRITE As Int32 = &H2
> Const FILE_ATTRIBUTE_NORMAL As Int32 = &H80
>
> <StructLayout(LayoutKind.Sequential)> _
> Structure SECURITY_ATTRIBUTES
>     Public nLength As Int32
>     Public lpSecurityDescriptor As IntPtr
>     Public bInheritHandle As Boolean
> End Structure
>
> Declare Auto Function CreateFile Lib "kernel32" ( _
>     <MarshalAs(UnmanagedType.LPTStr)> ByVal lpFileName As String, _
>     ByVal dwDesiredAccess As Int32, _
>     ByVal dwShareMode As Int32, _
>     ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, _
>     ByVal dwCreationDistribution As Int32, _
>     ByVal dwFlagsAndAttributes As Int32, _
>     ByVal hTemplateFile As IntPtr _
> ) As IntPtr
>
> If this doesn't work try changing the lpSecurityAttributes parameter to
> ByVal instead of ByRef
>
>     /claes
>
>
Author
30 Mar 2006 5:57 AM
news.microsoft.com
That did it.
Thank you all.

Show quoteHide quote
"Claes Bergefall" <claes.bergefall@nospam.nospam> wrote in message
news:emIHlfzUGHA.2704@tk2msftngp13.phx.gbl...
> See inline
>
> "Al Reid" <arei***@reidDASHhome.com> wrote in message
> news:%23aWLuJzUGHA.5996@TK2MSFTNGP10.phx.gbl...
> > That's because you changed the Longs to Int32, which was no change at
all.
> > You need to use either Integer or Int16.  A DWORD is two
> > (2) 8 bit words or a 16-bit integer.
> >
>
> Ehh, no. A DWORD is 32 bits, same as Long in VB6 and Int32/Integer in
VB.NET
>
>
> > --
> > Al Reid
> >
> > "news.microsoft.com" <Yves_no_spam@hotmail.com> wrote in message
> > news:eCuZkBzUGHA.5900@tk2msftngp13.phx.gbl...
> >> I've changed the code with no luck:
> >>
> >> Declaration:
> >> *********
> >> Const FILE_READ_DATA = 1
> >> Const OPEN_EXISTING = 3
> >> Const FILE_SHARE_READ = &H1
> >> Const FILE_SHARE_WRITE = &H2
> >> Const FILE_ATTRIBUTE_NORMAL = &H80
> >>
> >> <StructLayout(LayoutKind.Sequential)> _
> >> Structure SECURITY_ATTRIBUTES
> >>     Public nLength As Int32
> >>     Public lpSecurityDescriptor As IntPtr
> >>     Public bInheritHandle As Boolean
> >> End Structure
> >>
> >> Declare Auto Function CreateFile Lib "kernel32" ( _
> >>     ByVal lpFileName As String, _
> >>     ByVal dwDesiredAccess As Int32, _
> >>     ByVal dwShareMode As Int32, _
> >>     ByRef lpSecurityAttributes As IntPtr, _
> >>     ByVal dwCreationDistribution As Int32, _
> >>     ByVal dwFlagsAndAttributes As Int32, _
> >>     ByVal hTemplateFile As IntPtr _
> >> ) As IntPtr
> >>
> >> Call:
> >> ****
> >> Dim fh As IntPtr
> >>
> >> fh = CreateFile("c:\test\test.txt", FILE_READ_DATA, FILE_SHARE_READ,
> >> IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)
> >>
> >> If fh.ToInt32 = -1 Then
> >>    MessageBox.Show("Invalid")
> >> End If
> >>
> >>
> >> I don't see what's wrong ...
> >>
>
> Try this:
>
> Const FILE_READ_DATA As Int32 = 1
> Const OPEN_EXISTING As Int32 = 3
> Const FILE_SHARE_READ As Int32 = &H1
> Const FILE_SHARE_WRITE As Int32 = &H2
> Const FILE_ATTRIBUTE_NORMAL As Int32 = &H80
>
> <StructLayout(LayoutKind.Sequential)> _
> Structure SECURITY_ATTRIBUTES
>     Public nLength As Int32
>     Public lpSecurityDescriptor As IntPtr
>     Public bInheritHandle As Boolean
> End Structure
>
> Declare Auto Function CreateFile Lib "kernel32" ( _
>     <MarshalAs(UnmanagedType.LPTStr)> ByVal lpFileName As String, _
>     ByVal dwDesiredAccess As Int32, _
>     ByVal dwShareMode As Int32, _
>     ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, _
>     ByVal dwCreationDistribution As Int32, _
>     ByVal dwFlagsAndAttributes As Int32, _
>     ByVal hTemplateFile As IntPtr _
> ) As IntPtr
>
> If this doesn't work try changing the lpSecurityAttributes parameter to
> ByVal instead of ByRef
>
>     /claes
>
>
Author
29 Mar 2006 1:48 PM
Herfried K. Wagner [MVP]
"news.microsoft.com" <Yves_no_spam@hotmail.com> schrieb:
> i'm having problems to call a api dll in vb dot net.
> I absolutely want to use this api call and none of the frame calls.

Any reason for using 'CreateFile' instead of .NET's 'System.IO.FileStream'
class or similar classes?

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>