Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. API in C# the func WRITE FILE

API in C# the func WRITE FILE

Scheduled Pinned Locked Moved C#
csharpjsontutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    barak160487
    wrote on last edited by
    #1

    hello, I have a pci card and i have the path of the port in a string value (//.////) in the write file func the value "hport" is in intptr; 1) I would happy if someone give an example of using in the fnction WriteFile 2) how I convert STRING TO INTPTR

    L 1 Reply Last reply
    0
    • B barak160487

      hello, I have a pci card and i have the path of the port in a string value (//.////) in the write file func the value "hport" is in intptr; 1) I would happy if someone give an example of using in the fnction WriteFile 2) how I convert STRING TO INTPTR

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, this is an example that writes a text string to a pipe using WriteFile. For P/Invoke you can have several prototypes with different sets of arguments; there is no need to convert to IntPtr yourself. BTW if you provide a string or StringBuilder it will convert Unicode to 8-bit ASCII by default.

      private void SendString(StringBuilder sb) {
      IntPtr pipe2=CreateFile(pipeName, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
      Thread.Sleep(200);
      int count;
      bool OK=WriteFile(pipe2, sb, sb.Length, out count, 0);
      if (!OK) ... report error
      ClosePipe(pipe2);
      }

      // Writes data to a file at the position specified by the file pointer.
      [DllImport("kernel32.dll", SetLastError=true)]
      public static extern bool WriteFile(
      IntPtr hHandle, // handle to file
      StringBuilder lpBuffer, // data buffer
      int nNumberOfBytesToWrite, // number of bytes to write
      out int lpNumberOfBytesWritten, // number of bytes written
      uint lpOverlapped // overlapped buffer
      );

      :)

      Luc Pattyn [My Articles]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups