TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Take Wata
NA
1
0
passing a struct through a namedpipe
May 28 2009 6:38 AM
Hi. I got a problem with a program made up with 2 modules. The 1st written in C++ that generates data and the 2nd one that reads data. The transmission take place through a NamedPipe that transport data from "c++" to "c#". Data are in form of structure.
Sending a simple integer isn't a problem but when I try to send a struct, i got a problem in the C# module that seems not able to transform data in the read buffer to the original struct.
This is a simplified code i wrote:
C++ SIDE
npipe = CreateFile("\\\\.\\pipe\\TestChannel",
GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);
struttura _s;
_s.numero = 12;
WriteFile(npipe, &_s, sizeof(struttura), &bread, NULL)
C# SIDE
[StructLayout(LayoutKind.Sequential)]
public struct struttura {
public int numero;
}
FileStream fStream = new FileStream(clientPipeHandle, FileAccess.ReadWrite, BUFFER_SIZE, true);
byte[] buffer = new byte[BUFFER_SIZE];
ASCIIEncoding encoder = new ASCIIEncoding();
struttura _s;
_s.numero = -1;
fStream.Read(buffer, 0, System.Runtime.InteropServices.Marshal.SizeOf(_s.GetType()));
IntPtr i = (IntPtr) System.Runtime.InteropServices.Marshal.SizeOf(_s);
_s = (struttura) System.Runtime.InteropServices.Marshal.PtrToStructure(i ,_s.GetType());
Reply
Answers (
1
)
file download
C# reading tables from a word document