any .NET developers here?

Post a reply

:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review

Expand view Topic review: any .NET developers here?

.NET and Events

by Mike H » Fri Sep 14, 2007 5:04 pm

I wrote my podcast plugin using .NET, the only way I could get events to work was using a vbscript to hook the events into the .NET object. This works pretty well (even if it is unpleasantly hacky), you just have to make sure the .net assemblies are compiled with COM interfaces too.

This is the autorun script from mmPodcasts - the events handlers are set from within the .NET code: OnChangedSelection must not have a script property, so it has to be hooked from here:

Code: Select all

' Blurb

Option Explicit

Sub onStartUp
    dim podcasts, podcastOptions
	set podcasts = CreateObject("mmPodcasts.PodcastsPlugin")
	set SDB.objects("PodcastsPlugin") = podcasts
	podcasts.init SDB, Script
	' Register event handlers
	Script.RegisterEvent SDB, "OnChangedSelection", "handleChangedSelection"
End Sub

' Retrieves the PodcastsPlugin object
Function podcasts()
    set podcasts = SDB.objects("PodcastsPlugin")
End Function

' Event Handlers
Sub handleUpdateDirectory(control)
End Sub

Sub handleDownloadPodcasts(control)
End Sub

Sub handleFillTracks(node)
End Sub

Sub handleChangedSelection
End Sub

Sub handleImport
End Sub

Sub handleExport
    Msgbox "Handle Export"
End Sub

by G.I. » Thu Sep 06, 2007 2:29 pm

I program a lot in .Net, but I have only experience in (little bit of) windows / (plenty of) web applications that are on it's own. Not plugins or any other application that uses winapi or other windows applications... so I am not sure if I am much help. But if you want some, just let me know :)

by Steegy » Tue Sep 04, 2007 3:19 pm


First take a look in the wiki.

by holterpolter » Tue Sep 04, 2007 2:18 pm

Do you know how to convert the Delphi example in to test it in Visual Basic Express 2005?
How do I create the SongsDB.SDBApplication object?

by Peke » Fri Jun 15, 2007 5:53 pm

Steegy wrote:BTW: I'm using MM (and no, I'm not updating to the lastest one :))
I've used that version too MediaMonkey.exe Filesize 4,697,600 Bytes.

by Steegy » Fri Jun 15, 2007 5:27 pm

Why do you search For MediaMonkey.exe search for Window name Contain MediaMonkey and TMainForm.
I normally do that, using the API: FindWindow.
However, now I wanted to try to use only C# code (no P/Invoke, Interop, API, ... you name it). .NET's way is to give you (only) access to the running processes. It doesn't support searching for windows.

BTW: I'm using MM (and no, I'm not updating to the lastest one :))

by Peke » Fri Jun 15, 2007 2:53 pm

Steegy wrote:....but I didn't think it would be needed so soon
:) Why do you search For MediaMonkey.exe search for Window name Contain MediaMonkey and TMainForm.

Code: Select all

  Memo1.Lines.Append('Title: '+SDB.Player.CurrentSong.Title);
  Memo1.Lines.Append('Artist: '+SDB.Player.CurrentSong.Artist.Name);
  Memo1.Lines.Append('Album: '+SDB.Player.CurrentSong.Album.Name);
  Memo1.Lines.Append('Track: '+IntToStr(SDB.Player.CurrentSong.TrackOrder)+'/'+IntToStr(SDB.Player.CurrentSong.Album.Tracks.Count));
  Memo1.Lines.Append('Covers: '+IntToStr(SDB.Player.CurrentSong.AlbumArt.Count));
This one do test all that and for example result look like this
  • Title: Baci che si rubano
    Artist: Laura Pausini
    Album: Laura Pausini
    Track: 4/8
    Covers: 1

by Steegy » Thu Jun 14, 2007 11:05 pm

I must say that ScreenSaver do not work on my PC "No mediaMonkey Started"
That's probably because your MediaMonkey program file isn't named MediaMonkey.exe or MediaMonkey_debug.exe. A code change was planned for that, but I didn't think it would be needed so soon :)

Code: Select all

  Memo1.Lines.Append('Title: '+SDB.Player.CurrentSong.Title); 
  Memo1.Lines.Append('Artist: '+SDB.Player.CurrentSong.ArtistName); 
  Memo1.Lines.Albumname('Artist: '+SDB.Player.CurrentSong.ArtistName); 
Well, you don't test the Album, Artist or AlbumArt objects here. Title, AlbumName and ArtistName work just fine here too.

by Peke » Thu Jun 14, 2007 8:54 pm

:) I must say that ScreenSaver do not work on my PC "No mediaMonkey Started" :)

Just Testing In Delphi by creating Third party exe and all I used is:

Code: Select all

unit COMtest;


  Windows, Messages, SysUtils, Variants, Classes, Controls, Forms,
  StdCtrls, ComObj;

  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    { Private declarations }
    { Public declarations }

  Form1: TForm1;
  SDB: OleVariant;


{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
  SDB := CreateOleObject('SongsDB.SDBApplication');

procedure TForm1.FormShow(Sender: TObject);
  Memo1.Lines.Append('Title: '+SDB.Player.CurrentSong.Title);
  Memo1.Lines.Append('Artist: '+SDB.Player.CurrentSong.ArtistName);
  Memo1.Lines.Albumname('Artist: '+SDB.Player.CurrentSong.ArtistName);

And All is OK
Hmmm... I'll investigate Events later, Jiri have changed things there for better compatibility.

by Steegy » Thu Jun 14, 2007 4:55 pm

They're all null for me, when using C#.Net with songs that are in my database and have album, artist and albumart.
Using scripting, there is no problem.

Unfortunately MM doesn't log COM interaction, and if it does, it's clearly that MM2 (for me) doesn't query the Album, Artist and AlbumArt objects for C#.Net.
I do see logging (GetFileInfo, DB open SQL, ...) when using VBScript.

But, the most important thing is that it works in MM3 so in the future it should be fine.

I'm using a small rudimentary screensaver app to test it atm: (C#.Net2)
I'm currently 'looking' to get Winamp visualizations in the background.

by Peke » Thu Jun 14, 2007 12:11 pm

Above mentioned fields should be null (except maybe album art) if file is not in library but if it is in library I have no problems with them.

by Steegy » Thu Jun 14, 2007 10:13 am

SongData sub-objects don't seem to work through COM in MM2, e.g.
are always null.

However, in MM3 this all works fine and is certainly good news. Maybe other things will work well in MM3 too.

by Peke » Thu Jun 14, 2007 10:00 am

When I make third party app I use both COM and PostMessage (Win API) to ensure that all is OK also like you said COM connect can slow down a little.

by Steegy » Thu Jun 14, 2007 6:27 am

Using something like this

Code: Select all

SongsDB.SDBApplicationClass SDB = new SongsDB.SDBApplicationClass();
SDB.ShutdownAfterDisconnect = false;

works fine for me. The biggest issues I have is that I can't attach to events in MM (at least, I'm not notified of events) and the "connection" to MM isn't always stable (COM errors, and in extreme cases slow or no MM response)

BTW: As you notice I'm using MediaMonkey's COM/Scripting interface, not the API Messages. The interface is much more powerful and ".NET-able".

by Peke » Wed Jun 13, 2007 10:53 pm

OK May I suggest small thing?
Have you tried to control Winamp from C#? If yes Use same for MM and all should work. Except where is winamp.exe replace with mediamonkey.exe.