Imported DLL problem
-
Hi Im having a problem getting the code below to work.
compressorHnd = Avi.ICOpen(Avi.FOURCC.ICTYPE\_VIDEO, Avi.FOURCC.DIVX, Avi.ICMODE.ICMODE\_COMPRESS); pCV = new Avi.COMPVARS(); pCV.cbSize = Marshal.SizeOf(pCV); pCV.hic = compressorHnd; pCV.dwFlags = 1; pCV.fccHandler = Avi.FOURCC.DIVX; pCV.fccType = Avi.FOURCC.ICTYPE\_VIDEO; outbi = new Avi.BITMAPINFOHEADER(); outbi.biSize = Marshal.SizeOf(outbi); // 40 outbi.biWidth = 640; outbi.biHeight = 480; outbi.biPlanes = 1; outbi.biBitCount = 24; outbi.biCompression = 0; Avi.ICSeqCompressFrameStart(pCV, ref outbi); bool key = false; long size = 0; IntPtr r = (IntPtr)Avi.ICSeqCompressFrame(pCV, 0, image.ToArray(), ref key, ref size);
The code causes an "System.AccessViolationException: Attempted to read or write protected memory" exception on the last line. ICSeqCompressFrame is imported using the code,
\[DllImport("MSVFW32.dll")\] public static extern int ICSeqCompressFrame( COMPVARS pc, int uiFlags, byte\[\] lpBits, ref bool pfKey, ref long plSize );
Can anyone help me out?
-
Hi Im having a problem getting the code below to work.
compressorHnd = Avi.ICOpen(Avi.FOURCC.ICTYPE\_VIDEO, Avi.FOURCC.DIVX, Avi.ICMODE.ICMODE\_COMPRESS); pCV = new Avi.COMPVARS(); pCV.cbSize = Marshal.SizeOf(pCV); pCV.hic = compressorHnd; pCV.dwFlags = 1; pCV.fccHandler = Avi.FOURCC.DIVX; pCV.fccType = Avi.FOURCC.ICTYPE\_VIDEO; outbi = new Avi.BITMAPINFOHEADER(); outbi.biSize = Marshal.SizeOf(outbi); // 40 outbi.biWidth = 640; outbi.biHeight = 480; outbi.biPlanes = 1; outbi.biBitCount = 24; outbi.biCompression = 0; Avi.ICSeqCompressFrameStart(pCV, ref outbi); bool key = false; long size = 0; IntPtr r = (IntPtr)Avi.ICSeqCompressFrame(pCV, 0, image.ToArray(), ref key, ref size);
The code causes an "System.AccessViolationException: Attempted to read or write protected memory" exception on the last line. ICSeqCompressFrame is imported using the code,
\[DllImport("MSVFW32.dll")\] public static extern int ICSeqCompressFrame( COMPVARS pc, int uiFlags, byte\[\] lpBits, ref bool pfKey, ref long plSize );
Can anyone help me out?
Hi, AFAIK you can't pass arrays like that, you need to offer some help. Here[^] is a little article explaining some ways that do work. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
Hi Im having a problem getting the code below to work.
compressorHnd = Avi.ICOpen(Avi.FOURCC.ICTYPE\_VIDEO, Avi.FOURCC.DIVX, Avi.ICMODE.ICMODE\_COMPRESS); pCV = new Avi.COMPVARS(); pCV.cbSize = Marshal.SizeOf(pCV); pCV.hic = compressorHnd; pCV.dwFlags = 1; pCV.fccHandler = Avi.FOURCC.DIVX; pCV.fccType = Avi.FOURCC.ICTYPE\_VIDEO; outbi = new Avi.BITMAPINFOHEADER(); outbi.biSize = Marshal.SizeOf(outbi); // 40 outbi.biWidth = 640; outbi.biHeight = 480; outbi.biPlanes = 1; outbi.biBitCount = 24; outbi.biCompression = 0; Avi.ICSeqCompressFrameStart(pCV, ref outbi); bool key = false; long size = 0; IntPtr r = (IntPtr)Avi.ICSeqCompressFrame(pCV, 0, image.ToArray(), ref key, ref size);
The code causes an "System.AccessViolationException: Attempted to read or write protected memory" exception on the last line. ICSeqCompressFrame is imported using the code,
\[DllImport("MSVFW32.dll")\] public static extern int ICSeqCompressFrame( COMPVARS pc, int uiFlags, byte\[\] lpBits, ref bool pfKey, ref long plSize );
Can anyone help me out?
Looks to me like your pinvoke signature is wrong. Several of the items are declared as the items themselves, not as pointers like the actual function expects: pc lpBits pfKey plSize Use this tool to help you generate the pinvoke signatures: http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a0608523/CLRInsideOut2008_01.exe[^] And when you get them generated, please post them on www.pinvoke.net for others to use. I used that same tool to help me generate pinvoke signatures for the wifi DLL in Windows.