473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Creating Unidirectional Message-based Named Pipe

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
Nov 21 '05 #1
2 5043
Hi FB,

The name for this in VBNet is remoting, there is a sample for that in the
resource kit.

VB.net Resource kit
http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing the resource kit
http://msdn.microsoft.com/vbasic/vbr...q/#installvdir

I hope this helps?

Cor
Nov 21 '05 #2
Hi, Cor

I appreciate the suggestion. I am sorry to say that it did not provide the
information I needed to accomplish my goal. I have checked a lot of
different leads (anything I could find as an online reference) and it seems
that no one is doing this in VB.

Let me ask this, then.

In the server application, I have created a separate thread for this named
pipe server (see code below). I then create my pipe as a blocking pipe
(PIPE_WAIT) in this separate thread.

In the development environment, as I run this code, the main application
thread blocks as well as the child thread upon the pipe wait condition. The
question is this: this condition only occurs in the development environment,
right? Once compiled, a pipe block only affects the immediate thread?

Public Class SmCSLogPipeClass

Public Sub PipeToOPCcommSvc()

'create a pipe and read from it

Dim hPipe As Integer

Const pipeName As String = "\\.\pipe\SMC_NP_OCS_SLS"

Dim openMode, pipeMode As Integer

Dim byteIn, res, cbnCount As Integer

'Create the named pipe

openMode = PIPE_ACCESS_DUPLEX Or FILE_FLAG_WRITE_THROUGH

pipeMode = PIPE_WAIT Or PIPE_TYPE_MESSAGE Or PIPE_READMODE_MESSAGE

hPipe = CreateNamedPipe(pipeName, openMode, pipeMode, 10, 10000, 2000,
10000, IntPtr.Zero)

[etc]

end class

....some module code here...

Dim LogPipe As New SmCSLogPipeClass

Dim oCommThread As System.Threading.Thread

oCommThread = New Thread(New ThreadStart(AddressOf
LogPipe.PipeToOPCcommSvc))

oCommThread.Start()
Thanks much,
Fred Bourdelier, DBA
Krebs Engineers
Tucson AZ USA
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OE**************@TK2MSFTNGP09.phx.gbl...
Hi FB,

The name for this in VBNet is remoting, there is a sample for that in the
resource kit.

VB.net Resource kit
http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing the resource kit
http://msdn.microsoft.com/vbasic/vbr...q/#installvdir

I hope this helps?

Cor

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: jenny | last post by:
Hi, I am trying to find a VB way that would create a folder on all existing drives - the folder name would be the same on each drive. ie c:\backup, d:\backup, etc. But the folders would only be...
0
by: Hal Davison | last post by:
From what I've read, when accessing a PostgreSQL database the dataset returned is considered to be UniDirectional in that one cannot execute an effective 'MovePrior' when acessing the database...
4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
8
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
2
by: LIN | last post by:
Hello, Greetings. I am creating a web site which will contain lot of articles. I had been planning to create simple HTML page on the server everytime i posted a article (eg. article12.html )....
0
by: Ravi Ambros Wallau | last post by:
Hi: I've created a custom control - a grid that uses Infragistics to display some filters, the grid itself, and some buttons. Well, when using this control directly on WebForm, everything works...
15
by: David Thielen | last post by:
Hi; My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a subdirectory to display as part of the created page. However, the bitmap will not display due to a security violation. ...
16
by: tshad | last post by:
This is a little complicated to explain but I have some web services on a machine that work great. The problem is that I have run into a situation where I need to set up my program to access one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.