Network Pipes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lou

    #1

    Network Pipes

    I have a handle to a pipe, but the FileSystem object won't take an int in
    the constructor? How do I write to the pipe using the FileSystemObjec t?

    here is my code but the FileStream Line fails?????
    I do get a legimate pipe handle.

    int pipeHandle;
    pipeHandle = CreateFile(conn ectionString,

    GENERIC_READ | GENERIC_WRITE, 0, 0,

    OPEN_EXISTING, 0, 0);

    //FileStream myStream=new
    FileStream(pipe Handle,FileAcce ss.ReadWrite,tr ue,4095,false);

    FileStream sw=new FileStream(pipe Handle,FileAcce ss.ReadWrite);

    sw.Write(cmd);


  • Greg Beech [MSFT]

    #2
    RE: Network Pipes

    Use an IntPtr not an int. You should always use IntPtr for OS handles as
    this will also work on 64-bit platforms whereas int will not. I like to
    declare a using statement as follows in my P/Invoke files:

    using HANDLE = System.IntPtr;

    then you could do it like:

    HANDLE pipeHandle = CreateFile(...) ;
    FileStream fs = new FileStream(pipe Handle, ...);

    Hope this helps.

    Greg

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Comment

    Working...