Hi,
I know there are many questions in this subject but none of them help to resolve the issue I am currently facing.
Below is the signature of C Function from DJVULibre added in .NET code
[DllImport("C:\\Program Files\\DJVULIBRE\\LIBDJVULIBRE.dll", CharSet=CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] private unsafe static extern int ddjvu_page_render(IntPtr page, ddjvu_render_mode_t mode, IntPtr pagerect, IntPtr renderrect, IntPtr pixelformat, ulong rowsize, [Out][MarshalAs(UnmanagedType.LPArray)]byte[] imagebuffer);
Below is how I am calling this function in the c# code
byte* buffer = (byte *)Memory.Alloc(nSize); try { IntPtr ptr1 = (IntPtr)Memory.Alloc(Marshal.SizeOf(prect)); Marshal.StructureToPtr(prect, ptr1, false); IntPtr ptr2 = (IntPtr)Memory.Alloc(Marshal.SizeOf(rrect)); Marshal.StructureToPtr(rrect, ptr2, false); byte[] array = new byte[nSize]; fixed (byte* p = array) Memory.Copy(buffer, p, nSize); ddjvu_page_render(page, ddjvu_render_mode_t.DDJVU_RENDER_MASKONLY, ptr1, ptr2, fmt, (ulong)stride, array); } finally { Memory.Free(buffer); }
call to ddjvu_page_render in above code is throwing "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Prior to this post I must have tried all the option could find in various blogs. Appreciate any help, is almost a day I am clueless, your timely help could save my job