Solved

I'm having trouble with the CreateMailslot function.

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 41
MsgBox 2 61
passing parameter in sql procedure 9 68
converting visio 2010 to powerpoint 2010  - formatting issues 5 109
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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.
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…

697 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