I need to somehow notify the first instance of my app about an event from another instance. Basically, if somebody starts a new instance of my app, then the first instance should be activated. What's the best way to do this Tried to use Win32 "SendInput" func, and it didn't work as expected on WinXP x64.
Here is the code I used before on Win32, maybe somebody will see what's wrong with it (doesn't work on WinXP x64).
// --------------------------->
internal enum DeviceMessageType : uint
{
Mouse = 0,
Keyboard = 1,
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
internal struct Point
{
public int X; // LONG
public int Y; // LONG
}
[StructLayout(LayoutKind.Sequential)]
internal struct MouseMessage // MOUSEINPUT
{
public Point Position; // LONG X, LONG Y
public uint MouseData; // DWORD
public uint Flags; // DWORD
public uint TimeStamp; // DWORD
public UIntPtr ExtraInfo; // ULONG_PTR
}
internal enum KeyEvent : uint // DWORD
{
KeyUp = 0x0002
}
[StructLayout(LayoutKind.Sequential)]
internal struct KeyboardMessage // KEYBDINPUT
{
public ushort VirtualKey; // WORD
public ushort ScanCode; // WORD
public KeyEvent KeyEvent; // DWORD
public uint TimeStamp; // DWORD
public UIntPtr ExtraInfo; // ULONG_PTR
}
[StructLayout(LayoutKind.Explicit)]
internal struct DeviceMessageInfo // INPUT
{
[FieldOffset(0)]
public DeviceMessageType DeviceMessageType;
[FieldOffset(4)]
public MouseMessage MouseMessage;
[FieldOffset(4)]
public KeyboardMessage KeyboardMessage;
public DeviceMessageInfo(DeviceMessageType DeviceMessageType)
{
this.DeviceMessageType = DeviceMessageType;
this.MouseMessage = new MouseMessage();
this.KeyboardMessage = new KeyboardMessage();
}
public static readonly int SizeOf = Marshal.SizeOf(typeof(DeviceMessageInfo));
}
[DllImport("User32.dll", EntryPoint = "SendInput", ExactSpelling = true)]
public static extern uint Send(uint Count, [In] DeviceMessageInfo[] DeviceMessageInfo, int DeviceMessageInfoSize);
// <---------------------------
For more info about WinXP x64 glitch read this post: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=604188&SiteID=1
I would really appreciate it if somebody could make the code above work on WinXP x64

Application Notification
bookysmell2004
ashopson
efratian
I checked your declarations with WinUser.h, the only thing that's off is the use of Point in MouseMessage. Structure member alignment in 64-bit .NET might be throwing this off. Try going back to specifying these structure members in-line or use FieldOffset...
Jason Bolstad