Click here to Skip to main content
15,902,891 members
Home / Discussions / C#
   

C#

 
GeneralRe: making the computer restart after a setup program is finished Pin
AndrewCherry7-Dec-03 2:08
AndrewCherry7-Dec-03 2:08 
GeneralRe: making the computer restart after a setup program is finished Pin
Heath Stewart7-Dec-03 4:02
protectorHeath Stewart7-Dec-03 4:02 
GeneralRe: making the computer restart after a setup program is finished Pin
Terrence Benade7-Dec-03 2:31
Terrence Benade7-Dec-03 2:31 
GeneralMailmerge Pin
Anonymous5-Dec-03 6:56
Anonymous5-Dec-03 6:56 
GeneralRe: Mailmerge Pin
Roger Stewart5-Dec-03 10:08
professionalRoger Stewart5-Dec-03 10:08 
GeneralRe: Mailmerge Pin
Anonymous9-Dec-03 6:16
Anonymous9-Dec-03 6:16 
GeneralC# and Named pipes Pin
Spiros5-Dec-03 5:32
Spiros5-Dec-03 5:32 
GeneralRe: C# and Named pipes Pin
Heath Stewart5-Dec-03 7:08
protectorHeath Stewart5-Dec-03 7:08 
First, let me just say that .NET Remoting is the recommended way for inter-process communication - even over disparate networks like the Internet. See the System.Runtime.Remoting namespace for more information, or read the MS Press book, ".NET Remoting" (it's pretty good for both beginners and advanced developers alike).

Having said that, you have to P/Invoke the CreateNamedPipe function and create a SECURITY_ATTRIBUTES structure like so:
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr CreateNamedPipe(string name, int openMode, int pipeMode,
  int maxInstances, int outBufferSize, int inBufferSize,
  int defaultTimeout, ref SECURITY_ATTRIBUTES);
 
[StructLayout(LayoutLind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
  public int length;
  public IntPtr securityDescriptor;
  public bool inheritHandle;
}
If you don't want to worry about the SECURITY_ATTRIBUTES struct in the CreateNamedPipe method, you could probably change the param to a generic object and pass null when calling the method. See the SDK documentation for CreateNamedPipe for details about what else to pass.

Now, that returns you a handle (IntPtr in .NET). You can use that in a call to the constructor for FileStream:
IntPtr handle = CreateNamedPipe(@"\\.\pipe\Name123", ...);
Stream s = new FileStream(handle, FileAccess.ReadWrite);
Now you've got a Stream to work with using managed code.

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralTrouble playing a sound Pin
Shizam5-Dec-03 4:33
Shizam5-Dec-03 4:33 
GeneralRe: Trouble playing a sound Pin
Heath Stewart5-Dec-03 4:44
protectorHeath Stewart5-Dec-03 4:44 
GeneralRe: Trouble playing a sound Pin
Shizam5-Dec-03 5:15
Shizam5-Dec-03 5:15 
GeneralRe: Trouble playing a sound Pin
Heath Stewart5-Dec-03 5:22
protectorHeath Stewart5-Dec-03 5:22 
GeneralRe: Trouble playing a sound Pin
Shizam5-Dec-03 5:37
Shizam5-Dec-03 5:37 
GeneralRe: Trouble playing a sound Pin
Heath Stewart5-Dec-03 6:06
protectorHeath Stewart5-Dec-03 6:06 
GeneralRe: Trouble playing a sound Pin
Shizam5-Dec-03 6:30
Shizam5-Dec-03 6:30 
GeneralRe: Trouble playing a sound Pin
Heath Stewart5-Dec-03 6:39
protectorHeath Stewart5-Dec-03 6:39 
GeneralRe: Trouble playing a sound Pin
Shizam5-Dec-03 8:19
Shizam5-Dec-03 8:19 
GeneralRe: Trouble playing a sound Pin
Heath Stewart5-Dec-03 8:55
protectorHeath Stewart5-Dec-03 8:55 
GeneralRe: Trouble playing a sound Pin
Jerry Hammond5-Dec-03 16:20
Jerry Hammond5-Dec-03 16:20 
GeneralRe: Trouble playing a sound Pin
J. Dunlap5-Dec-03 9:17
J. Dunlap5-Dec-03 9:17 
GeneralIs it possible to disable the Messagebox/Dialog... Pin
Loke15-Dec-03 3:34
Loke15-Dec-03 3:34 
Questioninserting data into Access using C#?? Pin
Azel Low5-Dec-03 2:47
Azel Low5-Dec-03 2:47 
AnswerRe: inserting data into Access using C#?? Pin
Heath Stewart5-Dec-03 4:04
protectorHeath Stewart5-Dec-03 4:04 
GeneralRe: inserting data into Access using C#?? Pin
Azel Low5-Dec-03 4:10
Azel Low5-Dec-03 4:10 
GeneralRe: inserting data into Access using C#?? Pin
Heath Stewart5-Dec-03 4:32
protectorHeath Stewart5-Dec-03 4:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.