私はFileRead APIを使用しています。 私はWindows 7 x64を使用していて、私のコードは正常に動作しています。 新しいWindows 7 x86およびVS2008チームワークと.NET 2、3 + SP1 + SP2、3.5、3.5.1をインストールしました。 私は管理者としての私のコードを実行しますが、それでもfollwoingエラーが発生します。FileRead APIを使用している場合のAccessViolationException
AccessViolationException(Attempted to read or write protected memory. This is often an indication that other memory is corrupt.)
int nread = 0;
uint handle;
byte[] buff = new byte[1024];
string driveRoot = string.Concat("\\\\.\\", driveLetter);
uint hRoot = CreateFile(driveRoot,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
IntPtr.Zero,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
IntPtr.Zero);
if (hRoot != -1)
handle = ReadFile(hRoot, buff, 1024, nread, new System.Threading.NativeOverlapped());
あなたのハンドルがのIntPtrでなければなりませんが、それは、x86上の問題になることはありません。しかし、x64でも問題になっていたはずです。そしてnreadもポインタとして渡され、あなたはuintを渡しています。 IntPtrでなければなりません。 –