EDN Admin
Well-known member
Hello,
<p style="margin-bottom:0in I have an Application that creates images of SD Cards for my company that has been working under XP just fine. The application now does not work under Windows 7. The application opens the SD Card via a Physical Drive ( CreateFile()
) and was using FileStream access to writes and reads. I later discovered that administrative level was needed and I now an using WriteFile() and ReadFile(). The ReadFile() works fine, but the Write file only seems to only let me write the first 512 (MBR).
Is there anything I need to do different to write beyond the first 512? I tried Locking and different assortment of Flags for the CreateFile() but nothing. Please note again that I can write just file to the first 512. Below is a snippet, thanks in advance:
<div style="color:Black;background-color:White; <pre>
handleValue = CreateFile(
PhysicalDrivePath,
GENERIC_READ | GENERIC_WRITE,
0,
IntPtr.Zero,
OPEN_EXISTING,
FILE_FLAG_WRITE_THROUGH,
IntPtr.Zero);
<span style="color:Green; // Check if valid Handle
<span style="color:Blue; if (!handleValue.IsInvalid)
{
r = <span style="color:Blue; new StreamReader(sourceFilePath);
imageLength = r.BaseStream.Length;
<span style="color:Blue; int offset = 0;
<span style="color:Blue; while (offset < imageLength)
{
readData = <span style="color:Blue; new <span style="color:Blue; byte[512];
r.BaseStream.Read(readData, 0, 512);
<span style="color:Blue; uint cbThatWereWritten = 0;
<span style="color:Blue; bool result = WriteFile(
handleValue,
readData,
(<span style="color:Blue; uint)readSize,
<span style="color:Blue; ref cbThatWereWritten,
<span style="color:Blue; ref lpOverlapped);
<span style="color:Blue; if (!result || cbThatWereWritten == 0)
{
handleValue.Close();
r.Close();
<span style="color:Blue; return;
}
offset += (<span style="color:Blue; int)cbThatWereWritten;
lpOverlapped.OffsetHigh = offset;
}
r.Close();
handleValue.Close();
}
[/code]
View the full article
<p style="margin-bottom:0in I have an Application that creates images of SD Cards for my company that has been working under XP just fine. The application now does not work under Windows 7. The application opens the SD Card via a Physical Drive ( CreateFile()
) and was using FileStream access to writes and reads. I later discovered that administrative level was needed and I now an using WriteFile() and ReadFile(). The ReadFile() works fine, but the Write file only seems to only let me write the first 512 (MBR).
Is there anything I need to do different to write beyond the first 512? I tried Locking and different assortment of Flags for the CreateFile() but nothing. Please note again that I can write just file to the first 512. Below is a snippet, thanks in advance:
<div style="color:Black;background-color:White; <pre>
handleValue = CreateFile(
PhysicalDrivePath,
GENERIC_READ | GENERIC_WRITE,
0,
IntPtr.Zero,
OPEN_EXISTING,
FILE_FLAG_WRITE_THROUGH,
IntPtr.Zero);
<span style="color:Green; // Check if valid Handle
<span style="color:Blue; if (!handleValue.IsInvalid)
{
r = <span style="color:Blue; new StreamReader(sourceFilePath);
imageLength = r.BaseStream.Length;
<span style="color:Blue; int offset = 0;
<span style="color:Blue; while (offset < imageLength)
{
readData = <span style="color:Blue; new <span style="color:Blue; byte[512];
r.BaseStream.Read(readData, 0, 512);
<span style="color:Blue; uint cbThatWereWritten = 0;
<span style="color:Blue; bool result = WriteFile(
handleValue,
readData,
(<span style="color:Blue; uint)readSize,
<span style="color:Blue; ref cbThatWereWritten,
<span style="color:Blue; ref lpOverlapped);
<span style="color:Blue; if (!result || cbThatWereWritten == 0)
{
handleValue.Close();
r.Close();
<span style="color:Blue; return;
}
offset += (<span style="color:Blue; int)cbThatWereWritten;
lpOverlapped.OffsetHigh = offset;
}
r.Close();
handleValue.Close();
}
[/code]
View the full article