Go Back   Winamp Forums > Developer Center > Winamp Development

Reply
Thread Tools Search this Thread Display Modes
Old 13th October 2007, 03:00   #1
zeroxmxi
Junior Member
 
zeroxmxi's Avatar
 
Join Date: Apr 2004
Posts: 6
Getting filename of currently playing song.

Hi there, I know this has been asked many times in the forums and it's one of those things I still don't get it.

Some time ago, shaneh replied to one of my post regarding how I can get the filename. He offered two ways, one of which is to read from the process memory which he thinks it's not really cool and Microsoft might prevent that in the future.

The other way is to use a message-only window and sends a WM_COPYDATA message to the pewnd. This is cool, I managed to write a win32 C++ application, create a message-only window and when a WM_CREATE message is received in the event queue, it will send a WM_COPYDATA message to the pewnd and Winamp will trigger the WM_COPYDATA message in my application's event queue that's where I obtain the filename from the COPYDATASTRUCT. In summary the flow looks like this..

[main function]
create window class
create message only window
set up a message loop

[window procedure]
on WM_CREATE, send WM_COPYDATA message to pewnd
on WM_COPYDATA, get the filename
on WM_DESTORY, post quit message

That's about the simplest way I want to describe the application I created. It's a win32 unicode executable.

I have a few questions regarding this though.

That... all these set up just to get the filename is it really efficient, as compared to the not so recommended read process memory way?

And I have been wanting to create a DLL to be able to read the filename from winamp. Do I go through all that the same as I did for the win32 executable and apply it on win32 DLL?
I understand I have the HINSTANCE right from the DllMain entry point and I can write codes to create the message-only window. That's cool but what about the message loop in a DLL? Where do I put the message loop in a DLL code?

DllMain (entry point)
you've got HMODULE which is the HINSTANCE that can be used to create windows, how can I expose or make visible to exported function.

other exported functions outside DllMain (how can they access HINSTANCE?)

Please give me some valuable advice, thanks .
zeroxmxi is offline   Reply With Quote
Old 13th October 2007, 03:03   #2
zeroxmxi
Junior Member
 
zeroxmxi's Avatar
 
Join Date: Apr 2004
Posts: 6
What shaneh replied to me eons ago.

Quote:
Very roughly...

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

callbackinfo cbi;
cbi.callback = hWnd;
cbi.index = SendMessage(pewnd,WM_WA_IPC, IPC_PE_GETCURINDEX,0);
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.
}
}

You will need to make it actually work yourself, but you get the idea. You can also use readprocess memory calls, but thats not a very good idea. In theory Windows could block the ability for that for security reasons in future versions of windows, its already possible with particular configurations.


Public Function getfilename(index As Integer) As String

On Error Resume Next

Dim Trackpos As Long
Dim mpointer As Long
Dim temp, temphandle, hwndwinampp As Long
Dim ntemp, ptemp
Dim Data As String * 256

mpointer = SendMessage(h_winamp, WM_USER, index, 211) '212 is Title
'do interprocess magic:
temp = GetWindowThreadProcessId(h_winamp, temphandle)
hwndwinampp = OpenProcess(PROCESS_VM_READ, False, temphandle)
Data = Space(256)
'pull the data:
ntemp = ReadProcessMemory(hwndwinampp, mpointer, Data, 256, temp)
'bail out:
ptemp = CloseHandle(hwndwinampp)
getfilename = Left(Data, InStr(1, Data, Chr(0)) - 1)

'the following does not work, the callback does not get called! why not?:
Dim cds As COPYDATASTRUCT
Dim f As callbackinfo
f.callback = GetProcAddress(AddressOf callbackf)
f.index = 12
cds.lpData = VarPtr(f)
cds.cbData = 8
cds.dwData = IPC_PE_GETINDEXINFO
CopyDataSendMessage h_winamp, WM_COPYDATA, 0&, cds

End Function
Cheers.
zeroxmxi 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