ReadFile problem

G

GTi

StringBuilder text = new StringBuilder(lpNextSize+1, lpNextSize+1);
int pNumberOfBytesRead = text.Capacity;
try { result=win32.ReadFile(_Handle, text, text.Capacity, ref
pNumberOfBytesRead, 0); }
catch (Exception e) { _lastError = e; Console.WriteLine(e.Message);
return (null); }
Console.WriteLine(text + " Bytes=" + pNumberOfBytesRead + " " +
text.Length + " " + text.Capacity + " " + lpNextSize);
return (text.ToString());

[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
public static extern bool ReadFile(IntPtr hFile,
[MarshalAs(UnmanagedType.LPStr)]StringBuilder pBuffer, int
NumberOfBytesToRead, [MarshalAs(UnmanagedType.U4)]ref int
pNumberOfBytesRead, int Overlapped);

Gives me this output:
External component has thrown an exception.
ABCD|ABCDEFGHJKL|testing|THIS IS A TEST12340 Bytes=44 44 45 44

I must have done something wrong here:
External component has thrown an exception.<

Can anyone see where the problem is?
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Is Handler correctly initialized? How?

And why in the name of Hades you want to do this?
Use FileStream


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



GTi said:
StringBuilder text = new StringBuilder(lpNextSize+1, lpNextSize+1);
int pNumberOfBytesRead = text.Capacity;
try { result=win32.ReadFile(_Handle, text, text.Capacity, ref
pNumberOfBytesRead, 0); }
catch (Exception e) { _lastError = e; Console.WriteLine(e.Message);
return (null); }
Console.WriteLine(text + " Bytes=" + pNumberOfBytesRead + " " +
text.Length + " " + text.Capacity + " " + lpNextSize);
return (text.ToString());

[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
public static extern bool ReadFile(IntPtr hFile,
[MarshalAs(UnmanagedType.LPStr)]StringBuilder pBuffer, int
NumberOfBytesToRead, [MarshalAs(UnmanagedType.U4)]ref int
pNumberOfBytesRead, int Overlapped);

Gives me this output:
External component has thrown an exception.
ABCD|ABCDEFGHJKL|testing|THIS IS A TEST12340 Bytes=44 44 45 44

I must have done something wrong here:
External component has thrown an exception.<

Can anyone see where the problem is?
 
G

GTi

Ohh, I use mailslots.
One machine write to the slots and send a message
The other machine read it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top