Search code examples
c#64-bitunmanaged32bit-64bitintptr

Unmanaged code that doesn't run appropriately on 64bit platform


I am using a code which captures a frame from a video which I found in CodeProject

The code runs great on 32bit, the problem starts when I try to run on 64bit systems.

The exception thrown is "AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory has been corrupted"

I debugged in 32bit and in 64bit platforms and found where the problem is-

mediaType = new AMMediaType();

mediaDet.get_StreamMediaType(mediaType);

videoInfo = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.formatPtr, typeof(VideoInfoHeader));

After the second line I looked at mediaType contents and it is completely different in 64bit over 32, which causes the next line to throw the exception(mediaType.formatPtr has different value)

I assume the problem is with the type "IntPtr" which size is different on the 2 platforms(4 vs 8 bytes) the thing is that I don't know how to overcome this problem.

Any kind of help would be good, thanks in advance, Liran.


Solution

  • found the solution - the problem lies within the DirectShow DLL, FrameGrabber referenced an old version of the dll, I downloaded and replaced the reference with their latest DLL and problem solved.

    Thanks for your post, Liran.