Click to See Complete Forum and Search --> : Attempted to read or write protected memory. This is often an indication that other m


dhemittal
October 29th, 2009, 07:20 AM
Hi,

I have this error in "CopyMemory".
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

#region API
[DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory")]
private static extern void CopyMemory(IntPtr Destination, IntPtr Source, [MarshalAs(UnmanagedType.U4)] uint Length);
#endregion


IntPtr ipSource = m_bmdLogo.Scan0;
IntPtr ipDest = (IntPtr)(pBuffer.ToInt32() + ((w * 3) * N));

CopyMemory(ipDest, ipSource, ((uint)m_bmdLogo.Stride));

please help regarding this issue

Thanks !
dhemittal@gmail.com

Mutant_Fruit
October 29th, 2009, 08:36 AM
What exactly is it you're trying to accomplish? I suspect that you can accomplish your task without having to P/Invoke anything.

vcdebugger
October 30th, 2009, 12:13 AM
[DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory")]
private static extern void CopyMemory(IntPtr Destination, IntPtr Source, [MarshalAs(UnmanagedType.U4)] uint Length);

Here entry point should be the same name as the native function you are calling is n't it ??

also have you allocated memory for the destination pointer beforing passing it ??

Mutant_Fruit
October 30th, 2009, 08:51 AM
The whole point of 'EntryPoint' is so you can name the C# method whatever you want and still get the correct native function.