?
Solved

I'm having trouble with the CreateMailslot function.

Posted on 1997-05-16
2
Medium Priority
?
601 Views
Last Modified: 2006-11-17
I've been trying to use the CreateMailslot function from kernel32 and I keep getting an INVALID_HANDLE_VALUE returned by the call.

I've tried the following C++ code in a DLL and it works :-

#include <iostream.h>
#include <windows.h>

long create_slot (void);

HANDLE hM_slot;


BOOL WINAPI DllEntryPoint (HINSTANCE hDll, DWORD dwReason, LPVOID Reserved)

{
      switch (dwReason)
      {
            case DLL_PROCESS_ATTACH:
            {
                  break;
            }
            case DLL_PROCESS_DETACH:
            {
                  break;
            }
      }
      return TRUE;
}

long create_slot (void)
{
      hM_slot=CreateMailslot("\\\\.\\mailslot\\test_mail_slot",0,MAILSLOT_WAIT_FOREVER,(LPSECURITY_ATTRIBUTES) NULL);
      return hM_slot;
}

In VB 4.0 I tried the following :-

Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Boolean
End Type

Declare Function CreateMailslot Lib "kernel32" Alias "CreateMailslotA" (ByVal lpName As String, ByVal nMaxMessageSize As Long, ByVal lReadTimeout As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long

Global slot_num As Long
Global Const MAILSLOT_WAIT_FOREVER = (-1)


Private Sub Command1_Click()
    Dim security As SECURITY_ATTRIBUTES
    slot_num = CreateMailslot("\\.\mailslot\mailslottest", 0, MAILSLOT_WAIT_FOREVER, security)
    MsgBox slot_num
End Sub

It doesn't work! So I tried this :-

Declare Function CreateMailslot Lib "kernel32" Alias "CreateMailslotA" (ByVal lpName As String, ByVal nMaxMessageSize As Long, ByVal lReadTimeout As Long, lpSecurityAttributes As Any) As Long

Global slot_num As Long
Global Const MAILSLOT_WAIT_FOREVER = (-1)


Private Sub Command1_Click()
    slot_num = CreateMailslot("\\.\mailslot\mailslottest", 0, MAILSLOT_WAIT_FOREVER, Null)
    MsgBox slot_num
End Sub

Still doesn't work!
0
Comment
Question by:mikekr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
y96andha earned 200 total points
ID: 1426348
It has to do with the specification of the C value NULL. Use this code:

Private Declare Function CreateMailslot Lib "kernel32" Alias "CreateMailslotA" (ByVal lpName As String, ByVal nMaxMessageSize As Long, ByVal lReadTimeout As Long, ByVal lpSecurityAttributes As Long) As Long
Private slot_num As Long
Private Const MAILSLOT_WAIT_FOREVER = (-1)

Private Sub Command1_Click()
slot_num = CreateMailslot("\\.\mailslot\mailslottest", 0, MAILSLOT_WAIT_FOREVER, 0)
MsgBox slot_num
End Sub



0
 

Author Comment

by:mikekr
ID: 1426349
Thanks... It worked!!!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question