Solved

I'm having trouble with the CreateMailslot function.

Posted on 1997-05-16
2
564 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
2 Comments
 
LVL 5

Accepted Solution

by:
y96andha earned 100 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

777 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