472,337 Members | 1,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,337 software developers and data experts.

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.GetLastWin32Error() 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 3593
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("kernel32.dll", _
CharSet:=CharSet.Ansi, _
EntryPoint:="CreateFileA", _
ExactSpelling:=True, _
SetLastError:=True)> _
Public Shared Function CreateFile(
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Int32, _
ByVal dwSharedMode As Int32, _
ByRef lpSecurityAttributes As IntPtr, _
ByVal dwCreationDisposition As Int32, _
ByVal dwFlagsAndAttributes As Int32, _
ByRef hTemplateFile As IntPtr) As IntPtr
End Function

<DllImport("kernel32.dll", _
EntryPoint:="WriteFile", _
ExactSpelling:=True, _
SetLastError:=True)> _
Public Shared Function WriteFile(
ByRef hFile As IntPtr, _
ByRef lpBuffer As IntPtr, _
ByVal nNumberOfBytesToWrite As Int32, _
ByRef lpNumberOfBytesWritten 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 lpNumberOfBytesWritten, 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 lpNumberOfBytesWritten, 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 lpNumberOfBytesWritten, 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 #5

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

Similar topics

0
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...
1
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...
3
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
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...
1
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...
1
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...
0
by: vertigo | last post by:
Hello I receive some mailslot packets. Can i check from whom i have received them ? Thanx Michal
4
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++...
4
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...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.