writefile (coredll)
Last changed: 88.232.47.175

.
Summary
TODO - a short description

C# Signature:

[DllImport("coredll")]
static extern Boolean WriteFile(IntPtr fFile, Byte[] lpBuffer, UInt32 nNumberOfBytesToWrite,
        out UInt32 lpNumberOfBytesWritten, IntPtr lpOverlapped);

VB .NET Signature:

Declare Function WriteFile Lib "coredll.dll" (TODO) As TODO

VB Signature:

Public Declare Function WriteFile Lib "coredll" ( _
    ByVal hFile As Long, _
    ByVal lpBuffer As String, _
    ByVal nNumberOfBytesToWrite As Long, _
    lpNumberOfBytesWritten As Long, _
    ByVal lpOverlapped As Long) As Long

User-Defined Types:

Public Const CREATE_ALWAYS = 2
Public Const OPEN_ALWAYS = 4
Public Const GENERIC_READ = &H80000000
Public Const GENERIC_WRITE = &H40000000
Public Const FILE_END As Long = 2

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

Private Function WriteString(MyString As String) As Boolean
    Dim lWritten As Long
    Dim flag As Long
    Dim hFile As Long

    If optOverwrite Then
    flag = CREATE_ALWAYS
    Else
    flag = OPEN_ALWAYS
    End If

    hFile = CreateFile(txtFileName.Text, GENERIC_READ + GENERIC_WRITE, _
               0, 0, flag, 0, 0)

    If optAppend.Value Then
    SetFilePointer hFile, 0, 0, FILE_END
    End If

    If hFile <> -1 Then
    WriteFile hFile, MyString, LenB(MyString), lWritten, 0
    CloseHandle hFile
    End If
End Function

Alternative Managed API:

TODO

Documentation
WriteFile on MSDN