WCE 앱에서 파일 이름 (특정 파일의 이름/경로) 만 특정 메모리 주소로 복사 할 수있는 방법을 찾고 있습니다. Copy data from from IntPtr to IntPtr파일의 메모리 주소를 얻는 방법
[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
static void Main()
{
const int size = 200;
IntPtr memorySource = Marshal.AllocHGlobal(size);
IntPtr memoryTarget = Marshal.AllocHGlobal(size);
CopyMemory(memoryTarget,memorySource,size);
}
: 파일은 제한된 자원으로, I 메모리 (바이트 배열)에 전체 파일을 읽는 피하기 위해 기대했다 그래서,이 게시물에서 답을 사용하여, large'ish ~ 40메가바이트 오히려입니다 그로 인해 2 가지 문제가 생깁니다. 우선 : 어떻게 메모리 주소를 IntPtr에 할당합니까?, 종류 : int* startAddr = &0x00180000
둘째로 : 파일의 메모리 주소는 어떻게 얻을 수 있습니까? 즉 그것에 대해가는 유효한 방법이 될 것인가
[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
private unsafe void CopyFile()
{
try
{
fixed (Int32* startAddr = /*0x00180000*/)
{
fixed(Int32* fileAddr = /*Memory Address of file*/)
{
CopyMemory(new IntPtr(startAddr), new IntPtr(fileAddr), (uint)new FileInfo("File name").Length);
}
}
}
catch { }
}
:이 두 질문
내 코드가 같이 보일 것이다 대답?
도움을 주시면 감사하겠습니다. 미리 감사드립니다 !!
업데이트 : CopyMemory는 그 방법이 아닙니다. 그러니 무시하십시오.
또한 죄송합니다. 기본적으로 디스크의 파티션 시작 부분으로 파일을 옮기고 싶습니다. IntPtr이 디스크 주소를 가리킬 수도 있다고 생각했지만 회상에서 볼 수있는 것은 물론 볼 수 없습니다. 어쨌든 혼란을 드려 죄송합니다.
당신은 단순히에게 주소를 할당 할 IntPtr''의의 ctor를 사용할 수'새를 IntPtr을 (0x00180000)', 두 번째 부분 들어, 파일에는로드 할 때까지 메모리 주소가 없습니다. RAM에있는 것이 아니라 디스크에 있습니다. – aevitas
@aevitas 물론. 고마워. 당신이 옳습니다. CopyMemory가 최선의 방법이 아닐 수도 있습니다. – Viking