Solved

I'm having trouble with the CreateMailslot function.

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

809 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