473,729 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mailslot possible with proper PInvoke?

Ted
Is it possible to use mailslots in .NET using PInvoke?

I have a VC++ 6.0 based app that creates and listens to a
mailslot. I have a second VC++ 6.0 based app that opens
the mailslot and writes to it successfully. So this stuff
works.

Additionally, I have a VB.NET app that opens the mailslot
successfully using CreateFile() (with PInvoke). What looks
like a proper handle is returned and there is no error.
(Marshal.GetLas tWin32Error() returns 0).

However, when I try to use this handle (VB.NET app) with
WriteFile() (using PInvoke) the write fails with error
code 0x06, which is "The handle is invalid".

I have tried multiple versions of PInvoke signatures,etc.
with the same result.

IS IT AT ALL POSSIBLE TO USE MAILSLOTS WITH .NET?

Thank you,
Ted

Jul 19 '05 #1
4 3712
Ted,
I have tried multiple versions of PInvoke signatures,etc.
with the same result.
Please post your declarations so we can have a look.

IS IT AT ALL POSSIBLE TO USE MAILSLOTS WITH .NET?


I don't see why not.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Jul 19 '05 #2
Ted
Mattias,

I have also tried to pass the handle to WriteFile using a
ByVal parameter, but had the same result. (bad handle)

Thanks,
Ted
I have included my VB.NET declarations:

-----------------------------------------------------------
<DllImport("ker nel32.dll", _
CharSet:=CharSe t.Ansi, _
EntryPoint:="Cr eateFileA", _
ExactSpelling:= True, _
SetLastError:=T rue)> _
Public Shared Function CreateFile(
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Int32, _
ByVal dwSharedMode As Int32, _
ByRef lpSecurityAttri butes As IntPtr, _
ByVal dwCreationDispo sition As Int32, _
ByVal dwFlagsAndAttri butes As Int32, _
ByRef hTemplateFile As IntPtr) As IntPtr
End Function

<DllImport("ker nel32.dll", _
EntryPoint:="Wr iteFile", _
ExactSpelling:= True, _
SetLastError:=T rue)> _
Public Shared Function WriteFile(
ByRef hFile As IntPtr, _
ByRef lpBuffer As IntPtr, _
ByVal nNumberOfBytesT oWrite As Int32, _
ByRef lpNumberOfBytes Written As Int32, _
ByRef lpOverLapped As IntPtr) As Integer
End Function
-----------------------------------------------------
-----Original Message-----
Ted,
I have tried multiple versions of PInvoke signatures,etc. with the same result.


Please post your declarations so we can have a look.

IS IT AT ALL POSSIBLE TO USE MAILSLOTS WITH .NET?


I don't see why not.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
.

Jul 19 '05 #3
Ted,

With the exception of lpNumberOfBytes Written, all parameters you
currently have declared ByRef should be ByVal.

Also, FWIW, explicitly calling the ANSI version of CreateFile hurts
performance on NT based Windows versions. It's generally better to use
CharSet.Auto.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Jul 19 '05 #4
Ted
Mattias,

I found my bug, thank you VERY MUCH for your help.
Ted
-----Original Message-----
Mattias,

I have tried a number of ways including as you described:
With the exception of lpNumberOfBytes Written, all parameters you
currently have declared ByRef should be ByVal.


The result is the same. The handle used with WriteFile()
returns an invalid handle error.

Have you ever used mailslots with .NET successfully? Do
you have a small example of code using mailslots

with .NET?

Thanks,
Ted
-----Original Message-----
Ted,

With the exception of lpNumberOfBytes Written, all

parameters you
currently have declared ByRef should be ByVal.

Also, FWIW, explicitly calling the ANSI version of

CreateFile hurts
performance on NT based Windows versions. It's generally

better to use
CharSet.Aut o.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
.

.

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1368
by: aherzallah | last post by:
Hi every one I have a question, how can I create a MailSlot in .NET using C#, just like the windows API CreateMailslot (in case still not clear please see the link http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/about_mailslots.asp?frame=true)
1
3583
by: aherzallah | last post by:
Hi every one can anyone help me on how can I create/write/read from a MailSlot in .NET using C#, just like the windows API CreateMailslot, (in case still not clear please see the link http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/about_mailslots.asp?frame=true) thanks in advance
3
1615
by: chip | last post by:
I know it can be done in a dll, but is it possible to call a c++ / c function directly from c-sharp. -chip
3
3466
by: Brett Robichaud | last post by:
I have created a simple background thread to make one pinvoke call into a DLL I've created. My Winforms app spawns the thread in the form load event then go about it's business. The problem is that my form appears to be blocked while the background thread is running. I am very familir with threads in unmanaged code but am just getting into them in C#. Are there issues I need to be aware of with regards to threading a simple pinvoke...
1
5089
by: vertigo | last post by:
Hello Can i use mailslot mechnism in C# ? I could find API for mailslot only for C/C++ for example: HANDLE CreateMailslot( LPCTSTR lpName, DWORD nMaxMessageSize, DWORD lReadTimeout, LPSECURITY_ATTRIBUTES lpSecurityAttributes );
1
2469
by: vertigo | last post by:
Hello I've tried to create mailslot server, and send there some packets. On both sides every operation is successful, but on server side message do not appear. Is there any client under windowsXP which could send some mailslot packets to my host ? Is there any command (like netstat for TCP) which could detect mailslot server listening ?
0
1175
by: vertigo | last post by:
Hello I receive some mailslot packets. Can i check from whom i have received them ? Thanx Michal
4
1830
by: Ted | last post by:
Is it possible to use mailslots in .NET using PInvoke? I have a VC++ 6.0 based app that creates and listens to a mailslot. I have a second VC++ 6.0 based app that opens the mailslot and writes to it successfully. So this stuff works. Additionally, I have a VB.NET app that opens the mailslot successfully using CreateFile() (with PInvoke). What looks like a proper handle is returned and there is no error.
4
7163
by: Rainer Queck | last post by:
Hi NG, I am working on a project in VS2005 that has to comunicate with an older application, using MailSlots. As far as I know, I have to use pInvoke to achieve this. It would be greate, to have a little sample on how to do this, please not only the C# signature like: static extern IntPtr CreateMailslot(string lpName, uint nMaxMessageSize,
0
8913
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9280
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.