Go Back   Winamp Forums > Developer Center > Winamp Development

Reply
Thread Tools Search this Thread Display Modes
Old 26th April 2005, 11:47   #1
Grayda
Junior Member
 
Join Date: Apr 2005
Location: Australia
Posts: 3
Send a message via AIM to Grayda Send a message via Yahoo to Grayda
Visual Basic 6 - Song title

I just downloaded WA5, and was wondering:

Is there a way to get the song title from winamp using API calls in Visual Basic? All the codes and forum posts cover everything BUT getting just the song title. It would be nice if I could get the song title to use on my chat server as a goodie.

Does WA5 have it's own API, or do I really have to use the FindWindow API to extract the name? Just the artist - song title would be nice, because I know you can change the way the title is displayed in WA, and If someone does, then using FindWindow and GetWindowText could produce some backwards results

Can anyone help me? All help is appreciated.
Grayda is offline   Reply With Quote
Old 2nd May 2005, 08:06   #2
saivert
Banned
 
saivert's Avatar
 
Join Date: Jan 2001
Location: Norway
Posts: 927
A Delphi Pascal approach to the thing

There is a trick where you can use some allegedly debugging functions from the Win32 API to read into Winamp's process space. This requires some deep knowledge of the Win32 API and I suggest you to buy a Win32 programming book which covers all parts of the Win32 API (not just simple games and fancy MDI applications). Since I'm not used to program in VB (long time ago since I lasted did a public declare line) you must figure it out yourself. Here's some Delphi Pascal code that does get the title from an external app:

code:

{ This function can be used to send messages that
return PChar (char* in C/C++) from external apps (not plug-ins)
Tip: Use it to get title of song playing instead of
WAExtGetCurTitle }
function SendMessageRetStr(wnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): String;
var
dwProcessId: DWORD;
phandle: THandle;
P: Pointer;
C: Cardinal;
PB: Pointer;
B: Byte;
begin
Result := '';
GetWindowThreadProcessID(wnd,dwProcessId);
phandle := OpenProcess(PROCESS_VM_READ, False, dwProcessId);
if phandle = 0 then exit;
P := Pointer(SendMessage(wnd, uMsg, wParam, lParam));
PB := nil;
B := 0;
repeat
if not ReadProcessMemory(phandle,P,@PB,1,C) then break;
B := Byte(PB);
if B <> 0 then begin
Result := Result + Chr(B);
end;
P := Pointer(DWord(P)+1);
until (B=0);

CloseHandle(phandle);
end;




code:

var
pos: Integer;
title: PChar;
begin
pos := SendMessage(hwnd_winamp, WM_WA_IPC, 0, IPC_GETLISTPOS);
title := SendMessageRetStr(hwnd_winamp, WM_WA_IPC, pos, IPC_GETPLAYLISTTITLE);

{ Now you got a title as a PChar in title }

end;



If you understand a little about the code above you should be able to translate it to Visual Basic. Maybe someone else will do it for you if they feel like it.

I would also recommend you to program in Delphi Pascal as it is much more friendly with regard to plugin programming as you can call all of the Win32 API directly and can create DLL's that export custom functions without the need for a plugin wrapper (as do in VB). Delphi Pascal code executes very fast too and is efficient if you use the VCL and the memory management routines provided by Borland.

Delphi is easy to learn if you are used to VB as you can drop components on a form and write event handlers just as you did in VB.

Here is my Winamp SDK for Delphi installer:
http://inthegray.com/saivert/winamp-...for_delphi.exe
saivert is offline   Reply With Quote
Old 2nd May 2005, 11:29   #3
Grayda
Junior Member
 
Join Date: Apr 2005
Location: Australia
Posts: 3
Send a message via AIM to Grayda Send a message via Yahoo to Grayda
Thx. I do understand the code. It doesn't seem that hard to impliment. Just having a play around the variable 'title' returns a number. I'll have to have a play around with that. Thanks for replying to this, this has pointed me in the right direction. Maybe I'll post the code for other Visual Basic programmers here. I know of a few who would love this code
Grayda is offline   Reply With Quote
Old 2nd May 2005, 11:51   #4
shaneh
Major Dude
 
Join Date: Jan 2004
Location: Brisbane, Australia
Posts: 1,193
There is actually a callback IPC for the playlist window which should eliminate the need to do readprocessmemory calls (it calls back with a WM_COPYDATA). DrO's comments in the header suggest he couldnt get it to work, but itd be worth investigating. Itd be a strange thing to put in there if it didnt work.
shaneh is offline   Reply With Quote
Old 2nd May 2005, 12:44   #5
Grayda
Junior Member
 
Join Date: Apr 2005
Location: Australia
Posts: 3
Send a message via AIM to Grayda Send a message via Yahoo to Grayda
I saw some code for that, but it only returned the playlist number, not the title. Thanks for the callback info. I'll look into it tomorrow
Grayda is offline   Reply With Quote
Old 3rd May 2005, 08:11   #6
saivert
Banned
 
saivert's Avatar
 
Join Date: Jan 2001
Location: Norway
Posts: 927
Those ReadProcessMemory calls also requires Administrator privilegse, right? So you can't use it on a normal user that is logged on.
saivert is offline   Reply With Quote
Old 7th May 2005, 01:15   #7
THX
Junior Member
 
Join Date: May 2005
Posts: 1
This is indeed the problem: Administrator status is needed for the "querying process".

Another (and widely used) method is to scan all open window handles and get their title text. Winamp main window or the playlist editor will provide you with the needed information.

Only disadvantage is that you cannot use the option "scroll songtitle in taskbar", but some other programs that get the current playing song (like scripts for Miranda or mIRC) do it the same way apparently.

How to cycle through all windows handles is "easier" and "less dangerous" API code.
I'd recommend you www.allapi.net and escecially their program "API-Guide", although it sadly doesn't get updated for a while now anymore...
THX is offline   Reply With Quote
Old 7th May 2005, 01:34   #8
shaneh
Major Dude
 
Join Date: Jan 2004
Location: Brisbane, Australia
Posts: 1,193
The window title method is quite crap and loaded with problems.

This code works fine for me. It is basically the same as taken from ipc_pe.h. DrO comments that he couldnt get it working, though I suspect he was looking for the IPC_PE_GETINDEXINFORESULT window message instead of WM_COPYDATA.


HWND wawnd = FindWindow("Winamp v1.x", NULL);
HWND pewnd = (HWND)SendMessage(wawnd, WM_USER, 1, 260);

callbackinfo cbi;
cbi.callback = hWnd;
cbi.index = index;
COPYDATASTRUCT cds;
cds.dwData = IPC_PE_GETINDEXINFO;
cds.lpData = (void *)&cbi;
cds.cbData = sizeof(callbackinfo);

SendMessage(pewnd, WM_COPYDATA,0,(LPARAM)&cds);


hwndprc()
{
case WM_COPYDATA:
{
cds=(COPYDATASTRUCT*)lParam;
if (cds->dwData == IPC_PE_GETINDEXINFORESULT)
filename = cds->lpData.
}
}

As for coding it in shitty VB, I'll leave that as an exercise for the reader.

//edit: oops, the above is pseudocode, forgot the rules that you have to label it as such
shaneh is offline   Reply With Quote
Old 9th May 2005, 09:32   #9
saivert
Banned
 
saivert's Avatar
 
Join Date: Jan 2001
Location: Norway
Posts: 927
It's nothing wrong in coding in Visual Basic. It's a wonderful language for those who wants to start programming. I actually started with VB myself, then went on to Delphi and when I got Visual C++ 6.0 installed I really could start making some decent shit. Now I got Visual Studio .NET 2003 but still don't make .NET applications cos' I'm scared of the CLR. When Winamp goes .NET I might consider it. ;-)
saivert is offline   Reply With Quote
Old 9th May 2005, 09:36   #10
shaneh
Major Dude
 
Join Date: Jan 2004
Location: Brisbane, Australia
Posts: 1,193
Yeah VB is fine for certain applications. When you need something done quickly, or need something done easily. Or when there are some decent high level components you want to make use of.

But seriously, I wouldnt touch it for anything commercial or seriously produciton quality.
shaneh is offline   Reply With Quote
Old 17th May 2005, 19:33   #11
CaboWaboAddict
Forum Sot
(Major Dude)
 
CaboWaboAddict's Avatar
 
Join Date: Mar 2004
Location: Marietta, Ga. U.S.A.
Posts: 3,915
Quote:
Originally posted by shaneh
Yeah VB is fine for certain applications. When you need something done quickly, or need something done easily. Or when there are some decent high level components you want to make use of.

But seriously, I wouldnt touch it for anything commercial or seriously produciton quality.
HUH?

When I hear that arrogant shit, I am tempted to dismiss the person as well as the comment. Here is why...

I started out as a commercial C programmer in 1984 using Desmit C for the PC. My development system was a DOS based XT system with a HUGE 10 Meg hard drive. I got Turbo C 1.0 when it came out and was in heaven. (I also started writing code in Fortran 77 on PDP 11/44 and Modcomp minicomputers at this time.)

I graduated to C++ with Borland under DOS. Next I Started writing Windows code in C++ using Object Windows about 1993. When Borland went belly up we went with Visual C++.

My boss decided that all future projects would be written in VB about 6 years ago. I thought that was a big mistake then. Not now.

I have many apps in use in many nuclear facilities all over the world. One VB6 package is a three tiered app that uses UDP to distribute real time data from up to 2500 devices to hundreds of clients. That package contains over 50,000 lines of code and took a year to write. If this was written in C++, I would most likely still be writing it.

I really have to speak up when people slam VB. Sure it allowed (and even encouraged) a lot of sloppy coding practices. But when a system is well written, it is easy to delvelop and easily maintained. VB.NET is adressing the main concerns about poor coding practices.

Idiot's Advocate
My site (under construction)
CaboWaboAddict is offline   Reply With Quote
Old 17th May 2005, 23:55   #12
shaneh
Major Dude
 
Join Date: Jan 2004
Location: Brisbane, Australia
Posts: 1,193
Well thats why I said it was good for writing things quickly and easily. You are looking at it from the side of the developer, which of course it makes your life easier. I dont know the details of the project, but it sounds like something thats needs to be written quickly, maintained by teh developers, not sold to the general public etc etc, which isnt the production quality commercial type apps I was talking about. (well it may be production quality, but its not quite what i meant)

To put it antoher way, if you had the choice between a web browser written in C or VB, which would you choose? Would pay as much for MS Office if it were written in VB (and it showed)?

Sure, VB has its uses, I use it myself. But writing it in C/C++ is usually going to get you a better product if you are willing to put in the extra effort. Sometimes the extra effort is worth it, sometimes its not. But if there is another product out there that has gone to the effort, Id rather choose that.

Last edited by shaneh; 18th May 2005 at 01:16.
shaneh is offline   Reply With Quote
Old 19th May 2005, 21:06   #13
CaboWaboAddict
Forum Sot
(Major Dude)
 
CaboWaboAddict's Avatar
 
Join Date: Mar 2004
Location: Marietta, Ga. U.S.A.
Posts: 3,915
There are good programmers and bad. That has nothing to do with the language. The only things I could fault VB for is speed and size in VB6 and earlier, but that is irrelevant in .NET.

I feel it is a major mistake to write code in a language just because someone says it is better. It took me about a year to learn the real tricks to writing efficient code in VB. I had lots of performance issues to go back and fix in my code from that time.

I agree that each language has its own strengths, but the average Joe could never become proficient enough across multiple languages to write good code in any of them.

Regardless of all of that, the point I was trying to make is that people shouldn't be zealots when discussing programming languages. Once a person has chosen a path, he or she shouldn't be ridiculed because they are not using your language of choice. If you look back, this is the original reason I joined this forum. Every post made requesting help with VB was answered with something like "Why don't you switch to a real language like (insert language of choice here)." Think back to when you first started writing code. Would you have liked to get jabbed with a sharp stick everytime you wanted to ask a question?

Idiot's Advocate
My site (under construction)
CaboWaboAddict is offline   Reply With Quote
Old 28th May 2005, 08:30   #14
Xiphias
Junior Member
 
Join Date: May 2005
Location: Gippsland, Victoria, Australia
Posts: 1
Hi All,

I am looking to develop a Song Title plugin in VB .NET 2002, that will display the title as a personal message in MSN Messenger 7.0. I have looked around and noticed a few plugins that do this, but I reckon I could do better. I know the insides and outs of the MSN Messenger API, and I am quite advanced at coding in VB .NET, but I have no knowledge of C++, and little knowledge of the Win32 API, so I have not been able to work out the SDK. If someone could help me by providing some VB code that will obtain the currently playing song title, that doesn't involve getting it from the window title, I would be very happy.

Thanks,

Xiphias
Xiphias is offline   Reply With Quote
Old 31st May 2005, 15:50   #15
CaboWaboAddict
Forum Sot
(Major Dude)
 
CaboWaboAddict's Avatar
 
Join Date: Mar 2004
Location: Marietta, Ga. U.S.A.
Posts: 3,915
Please do a seach for Basic, VB, .NET, etc. to find what you are looking for. There are lots of examples here.

Idiot's Advocate
My site (under construction)
CaboWaboAddict is offline   Reply With Quote
Old 31st May 2005, 21:47   #16
saivert
Banned
 
saivert's Avatar
 
Join Date: Jan 2001
Location: Norway
Posts: 927
Okay, okay! As at I said. I too started with VB. And under .NET it does not matter what language you use as they all produce the exact same bytecode (CLR handles it).
And .NET promises efficient code also.

But the problem does not lay in the language. The problem is with the VB (not talkin .nET here) framework and compiler. It does not allow one to export custom functions from a DLL (except when making a OCX in which case the compiler takes care of it internally). And size of EXE's compiled with VB compiler is bigger than an EXE compiled by a C/C++ compiler. This is because the frameworks are different (still not mentioning .NET here).
saivert is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > Winamp Development

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