What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Plug-Ins » [C#] Write to MsgPlus Event Log

Pages: (2): « First [ 1 ] 2 » Last »
[C#] Write to MsgPlus Event Log
Author: Message:
andersona91
New Member
*


Posts: 1
Joined: Oct 2005
O.P. Huh?  [C#] Write to MsgPlus Event Log
Hello folks,

Just a quick question, how do you write to the MsgPlus event log in C#?

Thanks!

---- Anderson ----
10-03-2005 06:00 PM
Profile E-Mail PM Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: [C#] Write to MsgPlus Event Log
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;
    }

This post was edited on 10-05-2005 at 09:30 AM by J-Thread.
10-03-2005 06:21 PM
Profile E-Mail PM Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: [C#] Write to MsgPlus Event Log
Did you test it already? Does it work?
10-04-2005 07:14 PM
Profile E-Mail PM Find Quote Report
Jedimark
Full Member
***


Posts: 140
Reputation: 6
Joined: Apr 2002
RE: [C#] Write to MsgPlus Event Log
J: I wrote very similar code to you when I was trying to integrate my Music Logger Plus plugin with the MsgPlus event log but couldnt for the life get it to actually work (there were no compile problems). I tried your code aswell and no luck either.

I'm guessing that the call is getting rejected by MsgPlus for some security reasons.

How should I invoke the method?

andersona91: Did you get it to work?

- Mark
10-04-2005 09:50 PM
Profile PM Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: [C#] Write to MsgPlus Event Log
Ok I'll test it myself later. I assume that patchou did test his VB.NET code, so that must be correct.

If the VB.NET code works, this should also work in my opinion...
Sorry I made a little mistake in my code!

It does work now :-). Make sure you've got the option to log things on;). By the way, it isn't possible to write to the conversation logs, only to the "actions log" (don't know how it's called, in dutch it's the "gebeurtenissenlogboek".

This post was edited on 10-05-2005 at 03:09 PM by WDZ.
10-05-2005 05:48 AM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [C#] Write to MsgPlus Event Log
quote:
Originally posted by J-Thread
(don't know how it's called, in dutch it's the "gebeurtenissenlogboek").
Event Log

----

ps: try to not double post... If you wanna add something, edit your previous post...

;)

This post was edited on 10-05-2005 at 02:36 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
10-05-2005 02:35 PM
Profile PM Find Quote Report
Jedimark
Full Member
***


Posts: 140
Reputation: 6
Joined: Apr 2002
RE: [C#] Write to MsgPlus Event Log
J-Thread: Your code works (sort of) and mine doesn't so I'll just use yours lol (A)

Anyway, I have the AddEventEntry in a class called Utilities.cs and I made it "public static bool" so I could then do:

code:
MLP.Utilities.AddEventEntry(thisContact, language[18] + " " + thisTitle + " " + language[19] + " " + thisArtist);
But it doesn't work.

However, I can write to the EventLog if I call the method from "MainForm_Load", why is this?

The method I want it to be called from is simply:
code:
private bool addEventLog(string thisContact, string thisTitle, string thisArtist)
        {
            RegistryKey rootPath = Registry.CurrentUser.CreateSubKey("Software\\Jedimark\\Music Logger Plus");
            string logStatus = rootPath.GetValue("LogToPlus").ToString();
            if (logStatus.Equals("true"))
            {
                MLP.Utilities.AddEventEntry(thisContact, language[18] + " " + thisTitle + " " + language[19] + " " + thisArtist);
                return true;
            }
            return false;
        }
(and yes, the if statement does return "true" so it is executing the call)
10-06-2005 07:12 PM
Profile PM Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: [C#] Write to MsgPlus Event Log
About that static method, it should work indeed. I don't know what the problem is...

About the code you posted, I see a huge bug!
code:
private bool addEventLog(string thisContact, string thisTitle, string thisArtist)
{
RegistryKey rootPath = Registry.CurrentUser.OpenSubKey("Software\\Jedimark\\Music Logger Plus");
string logStatus = rootPath.GetValue("LogToPlus").ToString();
if (logStatus.Equals("true"))
{
MLP.Utilities.AddEventEntry(thisContact, language[18] + " " + thisTitle + " " + language[19] + " " + thisArtist);
return true;
}
return false;
}

I hope you use OpenSubKey and not CreateSubkey!

There is a better way to store booleans in the registry btw. Use a DWORD value, set it 1 for true and 0 for false.

Does it work when you make your addEventLog function static also?
10-06-2005 08:17 PM
Profile E-Mail PM Find Quote Report
Jedimark
Full Member
***


Posts: 140
Reputation: 6
Joined: Apr 2002
RE: [C#] Write to MsgPlus Event Log
Yeah you're right it should be OpenSubKey, a rushed method!

The addEventLog doesn't work if it's static, I tried that already! I'm actually well and truely stuck with this one... this is what working full time has done to me |-)
10-06-2005 08:48 PM
Profile PM Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: [C#] Write to MsgPlus Event Log
Ok I did test it and this works:

In Utilities.cs, make the following code:
code:
[ComVisible(false)]
public class Utilities
{
    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);

    public Utilities()
    {
    }
    public static bool AddEventEntry(string sUser, string sEvent)
....(here the rest of my function)

Then your other function should be:
code:
private bool addEventLog(string thisContact, string thisTitle, string thisArtist)
{
RegistryKey rootPath = Registry.CurrentUser.OpenSubKey("Software\\Jedimark\\Music Logger Plus");
string logStatus = rootPath.GetValue("LogToPlus").ToString();
if (logStatus.Equals("true"))
{
Utilities.AddEventEntry(thisContact, language[18] + " " + thisTitle + " " + language[19] + " " + thisArtist);
return true;
}
return false;
}

So remove the namespace. This should all work. By the way, do you see an error or something? How do you know it isn't working?
10-07-2005 08:08 AM
Profile E-Mail PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On