2014-02-06 36 views
0

我對X64BadImageFormatException處置

跑這裏是我的代碼:

ColorFileMapping = CreateFileMapping(new IntPtr(-1), IntPtr.Zero, 0x04, 0, _byteCount, null); 
ViewerImageData = MapViewOfFile(ColorFileMapping, 0xF001F, 0, 0, _byteCount); 

但是當我試圖將本IntPtr的我得到一個BadImageFormatException

可以請你解釋一下爲什麼?

public void Dispose() 
{    
    Marshal.FreeHGlobal(ViewerImageData); //here i get the exception 
    Marshal.FreeHGlobal(ColorFileMapping); 
} 
+0

我不混。我在工作X64一路 – Gilad

回答

2

它你打電話MapViewOfFile實際上是對Windows API函數MapViewOfFile打電話,那麼你不應該把它看作一個HGLOBAL。它是指向內存區域的指針,當你完成它時,你需要調用UnmapViewOfFile

此外,您從CreateFileMapping得到的HANDLE應通過致電CloseHandle關閉。

+0

它說這裏使用http://blog.tedd.no/2011/07/28/unsafe-kernel32-mapped-memory-bitmap-wpf/ InteropBitmap.Invalidate(); – Gilad

+1

@Androidy - 它不!如果你看他的代碼中的Dispose方法,他會調用UnmapViewOfFile和CloseHandle。 – Sean

+1

好的,謝謝我幫你。 – Gilad

相關問題