Creating Unidirectional Message-based Named Pipe

From: FB's .NET Dev PC (shroom_at_comcast.net)
Date: 09/20/04

  • Next message: One Handed Man \( OHM - Terry Burns \): "Re: Simple Math Question"
    Date: Mon, 20 Sep 2004 13:40:49 -0700
    
    

    I am writing two services in VB.NET, one of which needs to send text strings
    to the other. After reading, I
    decided (perhaps incorrectly) that named pipes would be the best
    interprocess communication method
    for this task.

    I set about creating, on the pipe's server side, a new thread which would
    instantiate a blocking inbound message pipe, and the
    client side which would write to that pipe when needed. Being on the same
    PC, security is not an issue (I think).

    I first tried MS example from the KB article
    (http://support.microsoft.com/?kbid=871044) plugged into my
    services at the appropriate locations (threads and all) and it works as
    advertised. The only problem there
    is that this is a bidirectional pipe that transports an integer and a byte
    array.

    I have spent a few days trying to change the code. The latest simple attempt
    is to change the pipe type to INBOUND.
    When I do so, I get an error 5 (Invalid procedure call) on the client side.
    (short PIPE_ACCESS_INBOUND=&H1s)

    I have tried changing the declaration of the sample to a string or 1
    dimensional Byte array (rather than an Integer) and get an
    error 1214 (type mismatch) in the Error object's LastDLLError. According to
    my Win32 API book (Appleman) this declaration is type ANY,
    so I should be able to change the type, as long as they match on both ends
    of the pipe, right?

    SERVER SIDE DECLARATION (from the KB article):
    Declare Function CreateNamedPipe Lib "kernel32" Alias "CreateNamedPipeA" _
    (ByVal lpName As String, ByVal dwOpenMode As Integer, _
    ByVal dwPipeMode As Integer, ByVal nMaxInstances As Integer, _
    ByVal nOutBufferSize As Integer, ByVal nInBufferSize As Integer, _
    ByVal nDefaultTimeOut As Integer, ByVal lpSecurityAttributes As IntPtr _
    ) As Integer

    Declare Function ConnectNamedPipe Lib "kernel32" _
        (ByVal hNamedPipe As Integer, ByVal lpOverlapped As Integer) As Integer

    Declare Function ReadFile Lib "kernel32" _
    (ByVal hFile As Integer, ByRef lpBuffer As INTEGER,
    _<<<<---------------------change here
    ByVal nNumberOfBytesToRead As Integer, ByRef lpNumberOfBytesRead As Integer,
    _
    ByVal lpOverlapped As Integer _
    ) As Integer

    CLIENT SIDE MATCHING DECLARATION:
    Public Declare Function CallNamedPipe Lib "kernel32" Alias "CallNamedPipeA"
    _
    (ByVal lpNamedPipeName As String, _
    ByRef lpInBuffer As INTEGER,
    _<<<<--------------------------------------------change here
    ByVal nInBufferSize As Integer, _
    ByRef lpOutBuffer As Byte, _
    ByVal nOutBufferSize As Integer, _
    ByRef lpBytesRead As Integer, ByVal nTimeOut As Integer) As Integer

    1) Does anyone have example code for such a pipe? (client to server
    communication, message-type, text messages)
    2) Does anyone have any idea why changing the declared type from integer to
    anything else causes such problems?
    3) Is there a good way to debug these problems with API calls?

    Sorry if I'm missing something obvious, I've only started switching to .NET
    for 3 weeks now...Please be gentle!
    Thanks!
    FB


  • Next message: One Handed Man \( OHM - Terry Burns \): "Re: Simple Math Question"

    Relevant Pages

    • Variable declaration question
      ... searched but am not even sure of what search terms apply. ... Dim strAlreadyAdded, strErrorMessage, strCannotAdd as String ... Public Sub Validate_MDI(ByRef strCannotAdd As String, ... be sure I force declaration, I don't want to leave it up to Access to ...
      (microsoft.public.access.modulesdaovba)
    • Re: I have two blocks in developing for PocketPC can someone help
      ... "GetDiskFreeSpaceEx" (ByVal lpDirectoryName As String, ByRef ... Apart from that it looks right to me, the declaration at least. ...
      (microsoft.public.pocketpc.developer)
    • Re: Pointer to an array of pointers
      ... > I havne't used this API call before, but can you post your declaration ... ByVal szFile As String, ByRef pclsidHandler As Long, ByVal lpfnCallback As Long, _ ... ByVal nStreams As Long, ByRef ppaviStream As Long, ByRef ppCompOptions As Long) As Long ...
      (microsoft.public.vb.general.discussion)
    • Re: Formula help
      ... The string is wrapped around a 250mm round pipe at the ends. ... Then each time another wrap is placed on top of the previous the round ... Diameter of the Top Pipe + the String thickness x the Number of layers ...
      (microsoft.public.excel.worksheet.functions)
    • Re: Formula help
      ... The string is wrapped around a 250mm round pipe at the ends. ... Then each time another wrap is placed on top of the previous the round ... Diameter of the Top Pipe + the String thickness x the Number of layers ...
      (microsoft.public.excel.worksheet.functions)