으로 변환하므로 파일을 읽기 위해 kernel32
에서 ReadFile
을 사용하고 있습니다. 다음은 SetFilePointer
및 ReadFile
의 도움으로 파일을 읽는 코드입니다. 나는이 기능을 사용하면(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
}
}
, 그것은 (다른 용도로) 작동하므로이 코드를 테스트하고 작품이다.
하지만 주된 문제는이 함수가 바이트를 string
에 넣는 매개 변수로 outdata
을 변환해야한다는 것입니다.
Encoding.Unicode
등 (모두 UTF)을 사용해 보았지만 작동하지 않습니다.
시도해 보셨습니까? string result = System.Text.Encoding.Default.GetString (outdata); 출력을 문자열로 변환 할 수 있는지 확인하십시오. – Saravanan
나는 그것을 시도했다. 아무런 결과도주지 않습니다 .. – newbie
반환 매개 변수 또는 참조 매개 변수가 없으면 함수는 아무 것도 넣지 않습니다 ... – knaki02