So, I'm experiencing a very weird issue with my little test application. And by issue, I mean it crashes... hard. No exception (at least, nothing that I could catch) is thrown, just the "Blah Blah has stopped responding..." message. It crashes ONLY when I run the app in x64, release mode and outside of the IDE. If I run it in x86 mode, or if I run it in the IDE in x64 or I run it standalone as DEBUG in x64 it works fine.
I've narrowed it down to my p/invoke PeekMessage call. So, I need the brilliant minds here to look at the crap I've written and tell me if I'm doing it right. Because, seriously, I'm about to lose my f**king mind. I've tried this on 2 computers and they both exhibit the same behaviour. I'm a little concerned that this could be a .NET 4.0 bug.
Anyway, here's my p/invoke code. Please let me know if you see anything odd or just plain stupid:
Here's the call to PeekMessage:
private static bool PeekMessage()
{
MSG message = new MSG(); // Message to retrieve.
return Win32API.PeekMessage(ref message, IntPtr.Zero, 0, 0, PeekMessageFlags.NoRemove);
}
Here's PeekMessage (NOTE: The suppress security attribute is on the class definition, so it is being applied):
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool PeekMessage(ref MSG msg, IntPtr hwnd, uint wFilterMin, uint wFilterMax, PeekMessageFlags flags);
Here's the MSG:
[StructLayout(LayoutKind.Sequential)]
internal struct MSG
{
/// <summary>Window handle.</summary>
public IntPtr hwnd;
/// <summary>Message to process.</summary>
public uint Message;
/// <summary>Window message parameter 1.</summary>
public uint wParam;
/// <summary>Window message parameter 2.</sum