S
Shawn August
Hello:
I am converting a working VB6 program to C#. During testing of the C#
version, I noticed the ReadFile API is crashing. The parameters going into
the this function are identical to the working VB6 version. I have tried
changing the returned buffer datatype from string to object. The program
does not crash (no work) if I remove the ref argument on the 2nd argument
within the ReadFile API ('psBuffer'). A quick API sniffer revealed:
"EXCEPTION_ACCESS_VIOLATION". Here's the code:
DEFINITION
==========
[DllImport("kernel32.dll", SetLastError = true)]
public static extern int ReadFile
(int hFile, ref string psBuffer, int nNumberOfBytesToRead,
ref int lpNumberOfBytesRead, ref OVERLAPPED olOverlapped);
CALL
====
// Read
try
{
this.c_sStringBuffer = new string(' ', (int)this.c_lRecLen);
liRC = Win32Support.ReadFile(this.c_intFileHndl, ref
this.c_sStringBuffer, (int)this.c_lRecLen, ref liBytesRead, ref
this.c_olMudt);
this.c_lBytesRead = (this.c_lBytesRead + liBytesRead);
}
catch(Exception ErrorException)
{
throw new ApplicationException("Could not read the specified file. " +
ErrorException.Message);
}
Any ideas?
-Shawn
I am converting a working VB6 program to C#. During testing of the C#
version, I noticed the ReadFile API is crashing. The parameters going into
the this function are identical to the working VB6 version. I have tried
changing the returned buffer datatype from string to object. The program
does not crash (no work) if I remove the ref argument on the 2nd argument
within the ReadFile API ('psBuffer'). A quick API sniffer revealed:
"EXCEPTION_ACCESS_VIOLATION". Here's the code:
DEFINITION
==========
[DllImport("kernel32.dll", SetLastError = true)]
public static extern int ReadFile
(int hFile, ref string psBuffer, int nNumberOfBytesToRead,
ref int lpNumberOfBytesRead, ref OVERLAPPED olOverlapped);
CALL
====
// Read
try
{
this.c_sStringBuffer = new string(' ', (int)this.c_lRecLen);
liRC = Win32Support.ReadFile(this.c_intFileHndl, ref
this.c_sStringBuffer, (int)this.c_lRecLen, ref liBytesRead, ref
this.c_olMudt);
this.c_lBytesRead = (this.c_lBytesRead + liBytesRead);
}
catch(Exception ErrorException)
{
throw new ApplicationException("Could not read the specified file. " +
ErrorException.Message);
}
Any ideas?
-Shawn