473,800 Members | 2,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_INB OUND=&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 "CreateNamedPip eA" _
(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 lpSecurityAttri butes As IntPtr _
) As Integer

Declare Function ConnectNamedPip e 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 nNumberOfBytesT oRead As Integer, ByRef lpNumberOfBytes Read 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 5066
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 SmCSLogPipeClas s

Public Sub PipeToOPCcommSv c()

'create a pipe and read from it

Dim hPipe As Integer

Const pipeName As String = "\\.\pipe\SMC_N P_OCS_SLS"

Dim openMode, pipeMode As Integer

Dim byteIn, res, cbnCount As Integer

'Create the named pipe

openMode = PIPE_ACCESS_DUP LEX Or FILE_FLAG_WRITE _THROUGH

pipeMode = PIPE_WAIT Or PIPE_TYPE_MESSA GE Or PIPE_READMODE_M ESSAGE

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

[etc]

end class

....some module code here...

Dim LogPipe As New SmCSLogPipeClas s

Dim oCommThread As System.Threadin g.Thread

oCommThread = New Thread(New ThreadStart(Add ressOf
LogPipe.PipeToO PCcommSvc))

oCommThread.Sta rt()
Thanks much,
Fred Bourdelier, DBA
Krebs Engineers
Tucson AZ USA
"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:OE******** ******@TK2MSFTN GP09.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
7213
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 created if they don't already exist, and if the drive happens to be one a folder cannot be created on (ie a cdrom drive) it would just be skipped without the code generating any errors. your help on this would be most appreciated. jenny
0
2013
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 using ODBC. Is this correct? -- Hal Davison Davison Consulting
4
561
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 number of window handle, because if I reduce to about 2 instances of each window, it can run. But not 20 instances of each window. Does anyone know what the problem is? is it really because it exceeds the maximum number of window handle?
6
3255
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." exception. The problem is that this exception isn't raised somewhere in a method, so it just shows up, and it causes the application to shut down. Is there anyway how to catch this kinds of exceptions? Can I put somewhere a
8
5971
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; this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ApplicantName", dataset.Tables.Columns.DataType, 50,
15
6752
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 javascript or vbscript it works. I will appreciate any help. I do the following (C#):
2
3780
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 ). Now, i want to show an advertisement on top of each of this html page. the ad banner has to be dynamically updated depending on date (period) the advertiser has planned to advertise for. So I thought of creating ASPx pages instead. Is it a good...
0
2136
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 really fine. No problems at all. But, when this control is placed inside a template of an Infragistics UltraWebTab control, somethings stranges happens: 1. When the WebForm is opened, an "Error Creating Control" message is displayed (for container...
15
2837
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. Everything is the default settings I believe. IIS is running under Local System. In IIS the DefaultAppPool is running under Network Service. Annonymous access uses the account IUSR_JASMINE (machine name is Jasmine).
16
2383
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 or another (could also be 3) different web servers to use these Web Services. The Web Services are identical on all the machines. I tried just changing the URL of the Web Services and cannot make it work. I then decided to create 2 identical web...
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10275
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10033
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.