Is your client looking for a programming or design skill that you don't have? Refer a project to us, earn up to $10,000 in referral commission.
Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Winamp basic controls

A quick tutorial about controling winamp from c# using DllImport's.

On Wednesday, March 31st 2004 at 02:17 AM
By Andy Jump (View Profile)
*****   (Rated 4.4 with 16 votes)
Contextual Ads
More C# Resources

This is a little tutorial on using
the DllIport to allow your app to interact with winamp.

You can download the Winamp 5 SDK here:

The information is all for c++ and is in headers but you can use this info
to help develop more of the advanced controls.

The interaction with winamp is done using a function called SendMessage in c++
there are premade libarys that will have this all done for you. In c# however
theres no inbuilt support for it so after a little digging around and some google
researching I found the solution lies in the User32.dll.

To be able to use the SendMessage function in the User32.dll we have to use

[DllImport("user32.dll", CharSet=CharSet.Auto)]

public static extern IntPtr FindWindow(

[MarshalAs(UnmanagedType.LPTStr)] string lpClassName, 

[MarshalAs(UnmanagedType.LPTStr)] string lpWindowName


[DllImport("user32.dll", CharSet=CharSet.Auto)]

static extern int SendMessageA(

IntPtr hwnd, 

int wMsg, 

int wParam, 

uint lParam


FindWindow is used to get the Window
Handler, this will be put into an unsafe pointer and provides the target (winamp)
for us to aim our messages at.

SendMessageA is the function that
will send the commands to ainamp.

The window name for winamp will always be a cirtain value so we define this
as our first constant:

  private const string m_windowName = "Winamp v1.x";

To tell winamp that we are sending it a command it needs a code for the type
of command being sent so our next constant is:

  const int WM_COMMAND = 0x111;

(Note the more advanced command use two other command types but these are both
beyond the scope of this tutorial)

Next we need a list of all the command codes that we can retrive from the winamp
SDK, for this example we just want the basic ones so we put these in as a list
of constants too:

const int WA_NOTHING = 0;

const int WA_PREVTRACK = 40044;

const int WA_PLAY = 40045;

const int WA_PAUSE = 40046;

const int WA_STOP = 40047; 

const int WA_NEXTTRACK = 40048;

const int WA_VOLUMEUP = 40058; 

const int WA_VOLUMEDOWN = 40059;

const int WINAMP_FFWD5S = 40060;

const int WINAMP_REW5S = 40061;

I've put pretty self explanetry names
on all these commands

And finally we need to bring it all together in some functions that we can call
to get the required results:

public void Stop()


IntPtr hwnd = FindWindow(m_windowName, null); 



public void Play() 

IntPtr hwnd = FindWindow(m_windowName, null); 



public void Pause()


IntPtr hwnd = FindWindow(m_windowName, null); 



public void PrevTrack()


IntPtr hwnd = FindWindow(m_windowName, null); 



public void NextTrack()


IntPtr hwnd = FindWindow(m_windowName, null); 



public void VolumeUp()


IntPtr hwnd = FindWindow(m_windowName, null); 



public void VolumeDown()


IntPtr hwnd = FindWindow(m_windowName, null); 



public void Forward5Sec()


IntPtr hwnd = FindWindow(m_windowName, null); 



public void Rewind5Sec()


IntPtr hwnd = FindWindow(m_windowName, null); 



As you can see all these commands
are used in the same format, you use Findwindow to get the WIndow handler for
winamp, the you feed that in along with the command type WM_COMMAND(0x111),
the command you want WA_STOP(40047) and finally just send it the WM_NOTHING(0)
since for this type of interaction this perameter isn't needed.


From here you can reference the rest
of the SDK and do a little research yourself and you'll soon have a wide range
of commands and be able to do some pretty funky stuff!!

Digg Digg It!     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by Mihai Potra on Thursday, April 1st 2004 at 09:20 PM

Any knowledge on how to retreive the current volume level or current song and time?

by Andy Jump on Wednesday, April 7th 2004 at 08:48 PM

will get the current track length in seconds or the current track position in milliseconds. It involves using a struct to send and retrive the appropriate information.

will get the current info about the eq but i dont think there is a way to get the current volume level unless you are making an accual plug-in for winamp (I haven't had time to work on that yet).

All this info and more is in the winamp 5 sdk ;) so it will be the best source of information to get an overall picture of what can and can't be done even if your not at a level to port the code over from c++ to c# yourself.

by SergiuPol on Wednesday, June 30th 2004 at 03:06 AM

Merlin Schumacher done an excelent work with his "WinampConsoleControl". Try it :)

by tfwarlord on Wednesday, December 12th 2007 at 06:11 PM

Nice guide mate, BUT you mide want to include that you have to using System.Runtime.InteropServices; before you can do the dll thing. Took my 3 hours to figure out :-/

by tfwarlord on Wednesday, December 12th 2007 at 06:20 PM

hmm andy, cant you give an example of the "IPC_GETOUTPUTTIME 105" and "IPC_GETEQDATA 127", i dont understand ? :-)

by harun on Saturday, April 18th 2009 at 01:48 AM

i have checked sdk but i couldn't find any code about SendMessage format and (const int WM_COMMAND = 0x111)

how did you find the parametres of SendMessageA method?

i need your explanation..thansk...

by MorenoLauri on Tuesday, May 25th 2010 at 05:03 AM

I strictly recommend not to hold off until you get enough money to buy all you need! You should take the or short term loan and feel yourself fine

by credit cards for people with no credit on Wednesday, December 14th 2011 at 10:03 AM

I am very trouble when i download file from local path from network path but this code is helped me and its very good and simple code i like it

by behzad on Thursday, January 2nd 2014 at 11:53 PM

Thank you very much.

by matina on Tuesday, April 26th 2016 at 02:30 PM

I am happy that you shared this useful info with us. Please stay us informed like this. Thanks for sharing. I need it for

Comment Comment on this tutorial
Name: Email:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs C# Job Search
My skills include:
Enter a City:

Select a State:

Advanced Search >>
Discover Geekpedia