Old 8th January 2011, 22:36   #1
user1000
Junior Member
 
Join Date: Jan 2011
Posts: 3
how to use sendmessage to control winamp

I am a beginner in programming c# programms with view skills.
My goal is to control Winamp extern.
I have searched the internet and found a solution: to use sendmessage to control Winamp (There seems to be no c# method available?!)

Example of the proposal (I have seen many variants of this):
[only relevant part]

const UInt32 WM_COMMAND = 0x111;
const int Winamp_STOP = 40047;

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(
[MarshalAs(UnmanagedType.LPTStr)] string lpClassName,
[MarshalAs(UnmanagedType.LPTStr)] string lpWindowName);

public IntPtr FindWinampWindow()
{return FindWindow("winamp", null);}

SendMessage(hwnd, WM_COMMAND, Winamp_STOP, 0);

--- But it is not working. I am not sure if the code is wrong or if the
problem is another (maybe wrong constants for winamp 5 and second I am on a 64-bit machine - there are discussions about using int or Intptr cause of the lenght).
--- my idea is that my Programm is not finding winamp (variable hwnd
is wrong?)
--- Because the Findwindow-method seems to be inconvenient I try to use
i = int; i = Process.GetProcessesByName("winamp")[0].Id; ..to get the
correct pid. Then the last command should be:
SendMessage(IntPtr(i), WM_COMMAND, Winamp_STOP, 0);
. On the first look its ok, because the integer i is the same pid as the pid in the taskmanager, so it should be right. But this is not working, too.

Someone knows what is going wrong? It would be nice from you to post the
correct code. After looking hours around and trying different solutions I am now
despairing..
Greetings.
user1000 is offline   Reply With Quote
Old 9th January 2011, 10:41   #2
DrO
 
Join Date: Sep 2003
Posts: 27,873
have a look at http://sourceforge.net/projects/winampminimagic/ though i've just not had the time or likely to for a while longer to sort out compiled versions of the source code but it should give a better idea of what is needed.

-daz
DrO is offline   Reply With Quote
Old 9th January 2011, 11:34   #3
user1000
Junior Member
 
Join Date: Jan 2011
Posts: 3
Thank you for your answer. It seems that the code is written in c and not c# and I have
less experience in c as in c#.
However, i will have a look at. Maybe I can get a solution if I examine that. (this will take
time...)

Still would be nice if someone else has an idea. Someone out there succeeded in
using Process.GetProcessesByName("winamp")[0].Id to get HWND and using sendmessage with that?
user1000 is offline   Reply With Quote
Old 9th January 2011, 12:20   #4
DrO
 
Join Date: Sep 2003
Posts: 27,873
there is an example c# app in the repository which is for using the library dll (once compiled) though if you look at the GetWinampHWND(..) function in the C code then you'll see there are a number of ways needed to reliably get a Winamp window handle.

unfortunately my C# experience lasted a month and a half and i've not done anything else on it in the 6months since then so i cannot really help out too much more. only thing would be trying to get around to releasing a proper copy of the plug-in for use as you've going to run into other issues with trying to do things against Winamp like string related things without the wrapper or an equivalent due to cross-process + managed to unmanaged fun.

-daz
DrO is offline   Reply With Quote
Old 9th January 2011, 15:07   #5
user1000
Junior Member
 
Join Date: Jan 2011
Posts: 3
Thanks again. OK. I found the sample. The solution seems to be more complicated as I have thought (relating to my experiences). I guess I will first need more practice before I will try to work with communication processes between different programs in that way.

I think that a plugin should be the more comfortable way to realize my idea. My first "zero-method" plugin have just been realized.... thanks for the sample on the "Beginners Basic Plugin Side". It's a litte pitty the code only is in c++. However - better than nothing and it should be a good starting point.

One last question in that relation. Is there any overview on how to trigger / calling winamp-functions form within a plugin? (e.g. how to use "play, stop, get filename and tag informations.")
Or have I to study the SDK-headers etc.?
regards.
user1000 is offline   Reply With Quote
Old 10th January 2011, 07:17   #6
DrO
 
Join Date: Sep 2003
Posts: 27,873
as Winamp is basically c/c++ most of the examples are going to be in that form and as it requires in-process plug-ins for most things to work then there has never really been any consideration done for C# / VB / other similar languages which don't give to being easily done in that way.

most of the api is either send a message when you want to do something or do it in response to a callback from Winamp's subclassed window (obviously this would assume having been done in a native plug-in) or for the ones which are defined in the plug-ins structure then they are called by Winamp as their name says.

-daz
DrO is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > Winamp Development

Tags
c-sharp, control, external, sendmessage

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump