J
Jim Lin
Has anyone successfully implemented a mailslot in VB.NET? The few examples
I've been able to find in VB are written in VB 6. Most of the examples I've
run across are written in C and about 10 years old.
I'm having difficulty getting the GetMailslotInfo call to give me useful
data (this might actually be a problem with CreateMailslot giving me a bogus
mailslot handle). CreateMailslot appears to be giving me a handle (it's not
giving me INVALID_HANDLE_VALUE).
Here's a code snippet from a little monitor program I whipped up to watch
for messages. Unfortunately, this half of the communications is normally
handled by a third party, so dumping mailslots in favor of some other mode
of communication is not possible.
Private Declare Function CreateMailslot Lib "kernel32" Alias
"CreateMailslotA" (ByVal lpName As String, ByVal nMaxMessageSize As Long,
ByVal lReadTimeout As Long, ByVal lpSecurityAttributes As
SECURITY_ATTRIBUTES) As Long
Private Declare Function GetMailslotInfo Lib "kernel32" (ByVal hfile As
Long, ByRef lpMaxMessageSize As Long, ByRef lpNextSize As Long, ByRef
lpMessageCount As Long, ByRef lpReadTimeout As Long) As Long
[...]
With sec
.bInheritHandle = False
.lpSecurityDescriptor = 0
.nLength = Len(sec)
End With
Debug.WriteLine("Creating handle to MailSlot")
Try
mailslotHandle = CreateMailslot(msName, 0, 0, sec)
'Check to see if a Mailslot was created successfully.
If mailslotHandle = INVALID_HANDLE_VALUE Then
Throw New Exception("Invalid handle value returned from
CreateMailSlot")
End If
Catch ex As Exception
'No mailslot available.
ErrorHandler("Mailslot not created", ex)
Exit Sub
End Try
'Main loop for the monitor.
Debug.WriteLine("Monitor starting")
While True = checkMail
'Read info about the mailslot. ***
System.NullReferenceException happening here ***
tmperr = GetMailslotInfo(mailslotHandle, maxsize,
msNextSize, msCount, msTimeout)
If (0 = tmperr) Then
tmperr = GetLastError()
Debug.WriteLine("Slot Info Error: " &
MessageText(tmperr))
skipTheRest = True
End If
[...]
Thanks for any help,
Jim
I've been able to find in VB are written in VB 6. Most of the examples I've
run across are written in C and about 10 years old.
I'm having difficulty getting the GetMailslotInfo call to give me useful
data (this might actually be a problem with CreateMailslot giving me a bogus
mailslot handle). CreateMailslot appears to be giving me a handle (it's not
giving me INVALID_HANDLE_VALUE).
Here's a code snippet from a little monitor program I whipped up to watch
for messages. Unfortunately, this half of the communications is normally
handled by a third party, so dumping mailslots in favor of some other mode
of communication is not possible.
Private Declare Function CreateMailslot Lib "kernel32" Alias
"CreateMailslotA" (ByVal lpName As String, ByVal nMaxMessageSize As Long,
ByVal lReadTimeout As Long, ByVal lpSecurityAttributes As
SECURITY_ATTRIBUTES) As Long
Private Declare Function GetMailslotInfo Lib "kernel32" (ByVal hfile As
Long, ByRef lpMaxMessageSize As Long, ByRef lpNextSize As Long, ByRef
lpMessageCount As Long, ByRef lpReadTimeout As Long) As Long
[...]
With sec
.bInheritHandle = False
.lpSecurityDescriptor = 0
.nLength = Len(sec)
End With
Debug.WriteLine("Creating handle to MailSlot")
Try
mailslotHandle = CreateMailslot(msName, 0, 0, sec)
'Check to see if a Mailslot was created successfully.
If mailslotHandle = INVALID_HANDLE_VALUE Then
Throw New Exception("Invalid handle value returned from
CreateMailSlot")
End If
Catch ex As Exception
'No mailslot available.
ErrorHandler("Mailslot not created", ex)
Exit Sub
End Try
'Main loop for the monitor.
Debug.WriteLine("Monitor starting")
While True = checkMail
'Read info about the mailslot. ***
System.NullReferenceException happening here ***
tmperr = GetMailslotInfo(mailslotHandle, maxsize,
msNextSize, msCount, msTimeout)
If (0 = tmperr) Then
tmperr = GetLastError()
Debug.WriteLine("Slot Info Error: " &
MessageText(tmperr))
skipTheRest = True
End If
[...]
Thanks for any help,
Jim