Editted again (this one does work):
code:
const int HWND_BROADCAST = 0xFFFF;
[DllImport("user32", EntryPoint="RegisterWindowMessageA")] public static extern int RegisterWindowMessage([MarshalAs(UnmanagedType.LPStr)]string lpString);
[DllImport("user32", EntryPoint="SendMessageA")] public static extern int SendMessage(int hwnd, int wMsg, int wParam, int lParam);
private struct MPL_EVENTLOG_INFO
{
public int sUser;
public int sEvent;
public int nReserved;
}
public bool AddEventEntry(string sUser, string sEvent)
{
MPL_EVENTLOG_INFO info = new MPL_EVENTLOG_INFO();
info.nReserved = 0;
System.Runtime.InteropServices.GCHandle userPtr = new System.Runtime.InteropServices.GCHandle();
if(sUser.Length < 1)
{
info.sUser = 0;
}
else
{
userPtr = System.Runtime.InteropServices.GCHandle.Alloc(sUser, System.Runtime.InteropServices.GCHandleType.Pinned);
info.sUser = userPtr.AddrOfPinnedObject().ToInt32();
}
System.Runtime.InteropServices.GCHandle eventPtr = new System.Runtime.InteropServices.GCHandle();
if(sEvent.Length < 1)
{
info.sEvent = 0;
}
else
{
eventPtr = System.Runtime.InteropServices.GCHandle.Alloc(sEvent, System.Runtime.InteropServices.GCHandleType.Pinned);
info.sEvent = eventPtr.AddrOfPinnedObject().ToInt32();
}
int nMsg = RegisterWindowMessage("MessengerPlus_AddEventLog");
System.Runtime.InteropServices.GCHandle infoPtr = System.Runtime.InteropServices.GCHandle.Alloc(info, System.Runtime.InteropServices.GCHandleType.Pinned);
int nResult = SendMessage(HWND_BROADCAST, nMsg, infoPtr.AddrOfPinnedObject().ToInt32(), 1);
if(info.sEvent != 0)
{
eventPtr.Free();
}
if(info.sUser != 0)
{
userPtr.Free();
}
infoPtr.Free();
return true;
}