T
Theewara Vorakosit
Hello,
I use CreateFile (p/invoke) to open my drive, which is a ramdisk. Then I
take a handle to FileStream constructor. There is an exception occur at
FileStream constructor. Here is my code.
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr CreateFile(
string filename,
[MarshalAs(UnmanagedType.U4)] FileAccess fileaccess,
[MarshalAs(UnmanagedType.U4)] FileShare fileshare,
int securityattributes,
[MarshalAs(UnmanagedType.U4)] FileMode creationdisposition,
int flags, IntPtr template);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args) {
IntPtr hDrv = CreateFile(
"\\\\.\\g:",
FileAccess.Read,
FileShare.ReadWrite,
0,
FileMode.Open,
0,
IntPtr.Zero);
FileStream fs = new FileStream(hDrv, FileAccess.Read);
Thereis IOException occur with "The parameter is incorrect." However, the
hDrv parameter can be used correctly with ReadFile (P/invoke).
Is this a limitation?
Thanks,
Theewara
I use CreateFile (p/invoke) to open my drive, which is a ramdisk. Then I
take a handle to FileStream constructor. There is an exception occur at
FileStream constructor. Here is my code.
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr CreateFile(
string filename,
[MarshalAs(UnmanagedType.U4)] FileAccess fileaccess,
[MarshalAs(UnmanagedType.U4)] FileShare fileshare,
int securityattributes,
[MarshalAs(UnmanagedType.U4)] FileMode creationdisposition,
int flags, IntPtr template);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args) {
IntPtr hDrv = CreateFile(
"\\\\.\\g:",
FileAccess.Read,
FileShare.ReadWrite,
0,
FileMode.Open,
0,
IntPtr.Zero);
FileStream fs = new FileStream(hDrv, FileAccess.Read);
Thereis IOException occur with "The parameter is incorrect." However, the
hDrv parameter can be used correctly with ReadFile (P/invoke).
Is this a limitation?
Thanks,
Theewara