473,386 Members | 1,757 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,386 software developers and data experts.

Named pipe class

Ok I am trying to make a named pipe class. I can open the server no problem
but when I open the client using CreateFile (which works) the thread then
locks on the SetNamedPipeHandleState. Basically I call the function and it
never returns. I am using the basic example in the online help. I would
expect either an error or success, not go to neverland. All the defines are
based on the SDK include file copied over.

Regards,
John

private string PipeName = @"\\.\pipe\myPipe";
private IntPtr hPort;

public PipeState Open()
{

UInt32 dwDesiredAccess = Win32Pipe.GENERIC_READ |
Win32Pipe.GENERIC_WRITE;
UInt32 dwSharedMode = 0;
UInt32 dwCreationDisposition = Win32Pipe.OPEN_EXISTING;
UInt32 dwFlags = 0;

this.hPort = Win32Pipe.CreateFile(this.PipeName,
dwDesiredAccess,
dwSharedMode,
IntPtr.Zero,
dwCreationDisposition,
dwFlags,
IntPtr.Zero);

if(this.hPort == (IntPtr)Win32Pipe.INVALID_HANDLE_VALUE)
{
int err = Marshal.GetLastWin32Error();
if(err == Win32Pipe.ERROR_PIPE_BUSY)
return PipeState.Busy;

Debug.WriteLine("Error opening client:" + err.ToString());
return PipeState.Error;
}
this.pipeState = PipeState.Opened;
Debug.WriteLine("Clent opened");

UInt32 type = Win32Pipe.PIPE_READMODE_MESSAGE | Win32Pipe.PIPE_WAIT;
bool retVal = Win32Pipe.SetNamedPipeHandleState(this.hPort, type, 0, 0);
if(!retVal)
{
Debug.WriteLine("Message Set Error:" +
Marshal.GetLastWin32Error().ToString());
return PipeState.Error;
}

return PipeState.Opened;
}
public class Win32Pipe
{
...
[DllImport("kernel32.dll")]
internal static extern bool SetNamedPipeHandleState(
IntPtr hNamedPipe,
UInt32 lpMode,
UInt32 lpMaxCollectionCount,
UInt32 lpCollectDataTimeout);

[DllImport("kernel32.dll")]
internal static extern IntPtr CreateFile(
string lpFileName,
UInt32 dwDesiredAccess,
UInt32 dwShareMode,
IntPtr lpSecurityAttributes,
UInt32 dwCreationDisposition,
UInt32 dwFlagsAndAttributes,
IntPtr hTemplateFile );

}
Nov 15 '05 #1
2 6378
John,
[DllImport("kernel32.dll")]
internal static extern bool SetNamedPipeHandleState(
IntPtr hNamedPipe,
UInt32 lpMode,
UInt32 lpMaxCollectionCount,
UInt32 lpCollectDataTimeout);


The last three parameters should be ref UInt32, or possibly IntPtr
passed by value if you want to pass a NULL pointer.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2
Thank you very much, works fine now...

Regards,
John
Nov 15 '05 #3

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

Similar topics

4
by: Rajarshi Guha | last post by:
Hi, I'm having a little trouble when I read from a named pipe. I create a pipe by os.mkfifo('/tmp/mypipe') and then open it for reading with fin = open('/tmp/mypipe','r+')
6
by: Srijit Kumar Bhadra | last post by:
Hello, Here is an example of Multithreaded Pipe Server and Client using the excellent ctypes library (Windows). Reference - MSDN:...
5
by: rajnish | last post by:
Hi Gurus, I am a newbee in C++ field. And I have been assigned to complete a task of create a template class, so that names pipes can be created using this template. I don't have a clue from...
5
by: richard | last post by:
I have a simple test to pass information from a client to a server using named pipe. what I really want is: when I type a line on the client, the server will output the line immediately. but to my...
4
by: Ken Allen | last post by:
Is there any built-in facility for handling named pipes in C#/.Net, or must one use unsafe code to access the WIN32 API directly? There exists some code that uses named pipes heavily and there...
3
by: EricR | last post by:
I am trying to use .NET to "tap into" a named pipe created by a non .NET 3rd party application. Specifically, the application is a table loading utility. It opens a named pipe and waits for input....
2
by: FB's .NET Dev PC | last post by:
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...
0
by: olaf.dietsche | last post by:
Hi, The system is Windows XP and DB2 v8.1.7. I'm trying to load a text file via named pipe into a table. I have two programs: the first program creates the named pipe, waits for a client...
7
by: andrewb | last post by:
Hi all, Having some trouble using named pipes and Visual Basic .NET and would appreciate and help you could offer. Essentially I am trying to develop a simple client/server application that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...

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.