Announcement

Collapse
No announcement yet.

Using CreateFile and WriteFile api HELP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ben Clark
    replied
    Thanks for all your help.
    I found the answer in a archived post.
    I changed the line from This:
    Result = WriteFile(hStdIO, Buffer, LEN(x), Written, 0)
    TO:
    Result = WriteFile(hStdIO, Buf, LEN(Buf), BYCOPY 0, BYVAL 0)

    Thanks again

    ------------------

    Leave a comment:


  • Semen Matusovski
    replied
    Ben --
    Such fragment (de-facto 100% your) works without problems on my PC (Win2000).

    Code:
    #Compile Exe
    #Include "Win32Api.Inc"
    DefLng A-Z
    Function PbMain
       Local Buffer As Asciiz * 1024
       Local SecAttrib As SECURITY_ATTRIBUTES
       SecAttrib.nLength = SizeOf(SecAttrib)
       SecAttrib.lpSecurityDescriptor = %NULL
       SecAttrib.bInheritHandle = %True
       FileNum = CreateFile("C:\FileIO5", _
          %GENERIC_READ Or %GENERIC_WRITE, _
          %FILE_SHARE_READ Or %FILE_SHARE_WRITE, SecAttrib, _
          %CREATE_ALWAYS, %FILE_ATTRIBUTE_NORMAL, %NULL)
       For i = 1 To 1000
          Buffer = "Line" + Str$(i) + " AT " + Time$ + $CRLF
          Result = WriteFile(FileNum, Buffer, Len(Buffer), Written, ByVal 0)
       Next
       CloseHandle FileNum
    End Function
    ------------------

    Leave a comment:


  • E B Knoppert
    Guest replied
    I use SecAttrib with ByVal 0&

    I runs ok on w95 to 2000

    ------------------

    Leave a comment:


  • Lance Edmonds
    replied
    What does GetLastError() return when the WriteFile() API fails? That is the clue you will need. If you still have problems, post a compilable example so we can duplicate your exact problem at our end.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Ben Clark
    started a topic Using CreateFile and WriteFile api HELP

    Using CreateFile and WriteFile api HELP

    Can anyone offer a little assistance?
    PB/DLL 6
    WinNT 4.0
    Pentium II - 400 MHz

    I am creating a file and trying to write to it.
    I am using the following code.

    LOCAL FileNum AS LONG
    LOCAL Count AS LONG
    LOCAL SecAttrib AS SECURITY_ATTRIBUTES

    SecAttrib.nLength = SIZEOF(SecAttrib)
    SecAttrib.lpSecurityDescriptor = %NULL
    SecAttrib.bInheritHandle = %True

    FileNum = CreateFile(FileIO, _
    %GENERIC_READ OR %GENERIC_WRITE, _
    %FILE_SHARE_READ OR _
    %FILE_SHARE_WRITE, _
    SecAttrib, _
    %CREATE_ALWAYS, %FILE_ATTRIBUTE_NORMAL, %NULL)

    This works and return me a file handle.
    Next I do this:
    LOCAL Buffer AS ASCIIZ * 1024
    LOCAL Written AS LONG
    LOCAL Result AS LONG

    Buffer = "Anything at all" + $NUL

    Result = WriteFile(FileNum, Buffer, LEN(Buffer), Written, 0)

    This ALWAYS fails. Result = 0 every time.
    Am I doing something wrong?
    I know this can be done with PB/DLL functions, but I need
    to do it this way.
Working...
X