Using CreateNamedPipe

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I am learning and trying to build an application in Visual Basic .NET for inter-process communication using Named Pipes. Is there a sample code on MSDN or anywhere whcih I can refer to?

Due to (apparent) lack of a Visual Basic .NET sample code on this topic, I am refering to Visual Basic 6.0 sample from MSDN. However, I am unable to create a named pipe using the CreateNamedPipe function as I am getting an error while passing security attribute (last argument) to CreateNamedPipe(szPipeName, dwOpenMode, dwPipeMode, 10, 10000, 2000, 10000, sa). Is there a way I can pass NULL to it, considering that Visual Basic .NET does not allow NULL?

Thanks
Rahul.
 
I am posting the relevant portion of the source code:
Relevant code:

Private sa As SECURITY_ATTRIBUTE
Private hPipe As Lon

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
Dim i As Long, dwOpenMode As Long, dwPipeMode As Lon
Dim res As Long, nCount As Long, cbnCount As Lon
For i = 0 To BUFFSIZE - 1 'Fill an array of number
BigBuffer(i) = i Mod 25
Next

'Create the NULL security token for the pip
pSD = GlobalAlloc(GPTR, SECURITY_DESCRIPTOR_MIN_LENGTH
res = InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION
res = SetSecurityDescriptorDacl(pSD, -1, 0, 0
sa.nLength = sa.ToString.Lengt

sa.lpSecurityDescriptor = pS
sa.bInheritHandle = Tru

'Create the Named Pip
MsgBox("creating pipe"
dwOpenMode = PIPE_ACCESS_DUPLEX Or FILE_FLAG_WRITE_THROUG
dwPipeMode = PIPE_WAIT Or PIPE_TYPE_MESSAGE Or PIPE_READMODE_MESSAG
MsgBox("before hpipe " & IsDBNull(sa)
hPipe = CreateNamedPipe(szPipeName, dwOpenMode, dwPipeMode,
10, 10000, 2000, 10000, sa) ' <--- Exception at this lin

The problem is what should be passed as the last parameter for the CreateNamedPipeMethod? If a NULL is to be passed then how to pass that?


----- Rahul wrote: ----

Hi

I am learning and trying to build an application in Visual Basic .NET for inter-process communication using Named Pipes. Is there a sample code on MSDN or anywhere whcih I can refer to?

Due to (apparent) lack of a Visual Basic .NET sample code on this topic, I am refering to Visual Basic 6.0 sample from MSDN. However, I am unable to create a named pipe using the CreateNamedPipe function as I am getting an error while passing security attribute (last argument) to CreateNamedPipe(szPipeName, dwOpenMode, dwPipeMode, 10, 10000, 2000, 10000, sa). Is there a way I can pass NULL to it, considering that Visual Basic .NET does not allow NULL?

Thanks
Rahul.
 
Rahul,

Make sure you translate the Declare statement to VB.NET properly. I
see you're using Long in yor code - they should most likely be changed
to Integers.

To pass NULL to the last parameter, declare it as ByVal IntPtr and
pass in IntPtr.Zero.



Mattias
 
Mattias,

I tried that but it does not work

----- Mattias Sjögren wrote: ----

Rahul

Make sure you translate the Declare statement to VB.NET properly.
see you're using Long in yor code - they should most likely be change
to Integers

To pass NULL to the last parameter, declare it as ByVal IntPtr an
pass in IntPtr.Zero



Mattia
 
Back
Top