2

IntPtr と、それが指すバイト数を指定する int を受け取りました。データには、null、EOL などの任意の文字を含めることができます。次のことを試みると、バッファが破損します。

//buffer is the IntPtr  
//count is the number of bytes in 'buffer'

byte[] test = new byte[count];  
Marshal.Copy(buffer, test, 0, count);

IntPtr ptr = IntPtr.Zero;  
ptr = Marshal.AllocCoTaskMem(count);  
Marshal.Copy(test, 0, ptr, count);  

「buffer」と「ptr」は異なるメモリ位置にある同じバッファ BLOB を指していると思いますが、そうではありません (同じデータを別のメモリ位置にコピーしているだけです)。ただし、「ptr」には DLL モジュールへの文字列参照が含まれているため、任意のメモリ位置を指しているように見えます。

何か案は?ありがとう!

4

0 に答える 0