そのため、ファイルの読み取りにReadFile
fromを使用しています。とkernel32
を使用してファイルを読み取るコードを次に示します。SetFilePointer
ReadFile
public long ReadFileMe(IntPtr filehandle, int startpos, int length, byte[] outdata)
{
IntPtr filea = IntPtr.Zero;
long ntruelen = GetFileSize(filehandle, filea);
int nRequestStart;
uint nRequestLen;
uint nApproxLength;
int a = 0;
if (ntruelen <= -1)
{
return -1;
}
else if (ntruelen == 0)
{
return -2;
}
if (startpos > ntruelen)
{
return -3;
}
else if (length <= 0)
{
return -5;
}
else if (length > ntruelen)
{
return -6;
}
else
{
nRequestStart = startpos;
nRequestLen = (uint)length;
outdata = new byte[nRequestLen - 1];
SetFilePointer(filehandle, (nRequestStart - 1), ref a, 0);
ReadFile(filehandle, outdata, nRequestLen, out nApproxLength, IntPtr.Zero);
return nApproxLength; //just for telling how many bytes are read in this function
}
}
この関数を使用すると、(別の目的で)機能するため、このコードはテストされ、機能します。
しかし、主な問題は、outdata
関数がバイトを に入れるパラメーターの を変換する必要があることstring
です。
など(全てUTF)を使ってみEncoding.Unicode
たのですが、うまくいきません。