|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: May 2005
Messaggi: 30
|
[C#] leggere struttura da pipe
Ciao a tutti....vi espongo il mio problema: ho un programma composto da un modulo scritto in C++ che genera dati, e un modulo scritto in C# che li legge.
Il mezzo che permette la comunicazione è una NamedPipe e i dati da inviare da C++ verso C# sono accorpati in una struttura. L'invio di un semplice int o di una stringa funziona...il problema è quando cerco di inviare tramite pipe una struttura. Vi lascio il codice che ho scritto LATO C++ Codice:
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)
Codice:
[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());
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 12:37.



















