Solved

I'm having trouble with the CreateMailslot function.

Posted on 1997-05-16
2
550 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
DO Loop not working 4 62
vba find the last empty column 10 81
Vb.net 2008 2 49
using web browser with BING 40 84
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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now