473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

ReadFile problem

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?

Nov 17 '05 #1
2 1871
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" <tu****@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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?

Nov 17 '05 #2
GTi
Ohh, I use mailslots.
One machine write to the slots and send a message
The other machine read it.

Nov 17 '05 #3

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

Similar topics

7
by: deko | last post by:
I need to allow users to download files from a directory that is not publicly accessible. To do this, I use a download script: header("Content-Type: application/octet-stream");...
0
by: Mustafa Ahmad Malik | last post by:
Hello, I have wrapped the Win32 pipes function in C#. I have created named pipe with PIPE_WAIT in pipemode parameter like this pipehandle = CreateNamedPipe(_pipeName, PIPE_ACCESS_DUPLEX,...
12
by: ORC | last post by:
Shouldn't 'ReadFile' block when timeouts are specified even when running in overlapped mode or am I wrong ??? Thanks Ole
2
by: Schorschi | last post by:
Can't seemd to get ReadFile API to work! Returns invalid handle error? =========================================================================== Ok, the visual basic gurus, help! The...
2
by: Spacetech | last post by:
Im trying to make it so I can read something out of a file and get it into a string so I can see if It matches what IM looking for. Here is what I got: HANDLE hFile; DWORD wmWritten; char...
0
friendjin
by: friendjin | last post by:
WriteFile(hCom1, "AT+CSQ\r", sizeof("AT+CSQ\r"), &dwWritten, &ovlw); Sleep(50); COMMTIMEOUTS comto; comto.ReadIntervalTimeout = 10; comto.ReadTotalTimeoutMultiplier =...
4
by: Eric Renken | last post by:
I am trying to do an Overlapped ReadFile on a HID device and it just isn't working for me. The WaitForSingleObject keeps giving me an error "The system cannot find the file specified." This...
1
by: mkarja | last post by:
Hi, I have a windows MDI program that draws some shapes that can be saved into a file and read from that file. The save seems to work with the WriteFile function, but for some reason the...
15
by: Ketchup | last post by:
Hello everyone, I have been stuck with this problem for quite some time now. I am working in VB.NET, using framework 1.0. I have to keep the compatibility down to the original .NET framework...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.