I am getting a PInvokeStackImbalance: 'PInvokeStackImbalance was detected Message: A call to PInvoke function 'ConvertedClass::MapViewOfFile' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.'
I am fairly new to DLL use, and just managed to work out a few tutorials today.
Any help would be appreciated.
using System.Runtime.InteropServices; //dll [DllImport("kernel32", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)] public static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, FileMapAccessRights dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow, ulong dwNumberOfBytesToMap;) string szSharedMemory = "FUNKY_BUSINESS"; //other dll call is successful and returns value IntPtr hMem = OpenFileMapping(FileMapAccessRights.Write, FALSE, szSharedMemory); ///BOOM.. not this one IntPtr pvHead = MapViewOfFile(hMem, FileMapAccessRights.Write, 0, 0, 0); Edit: It was a bad argument.. The 5th arg should be UIntPtr instead of ulong. this is how i feel right now
UIntPtr. Or you'll end up with the same problem when you switch to 64 bit process!SIZE_Tis unsigned so to be 100% accurate,UIntPtris the way to go.