Old 14th February 2010, 17:34   #1
corey.hannum
Junior Member
 
Join Date: Feb 2010
Posts: 2
SendMessage Enque Song in Playlist

Hello,

I'm trying to write a program in C# to do some basic Winamp functions (a functional SDK port instead of that which seems to be availalble for .net at SourceForge).

The really basic functions work (play, pause, stop, etc.) but I'm having some trouble with Enqueuing a song / sending a string.

The command arrives in Winamp, and winamp adds something to the playlist - unfortunatly not the string i wanted. It adds a bunch of garbage, and the garbage is always the same no matter what string i send (So I dont think it has to do with encoding)...

Following code:

[DllImport("user32.dll")]
public static extern int SendMessageA(int hwnd, int wMsg, int wParam, COPYDATASTRUCT lParam);

public struct COPYDATASTRUCT
{
public long dwData;
public long cbData;
public long lpData;
}

IntPtr temp;
COPYDATASTRUCT cds = new COPYDATASTRUCT();

cds.dwData = (long)IPC_PLAYFILE;
cds.lpData = (long)Marshal.StringToHGlobalUni(strURL);
cds.cbData = (long)strURL.Length + 1;

temp = Marshal.AllocHGlobal(Marshal.SizeOf(cds));
Marshal.StructureToPtr(cds, temp, false);

SendMessage(hwnd, WM_COPY_DATA, 0, (uint)temp);

Any suggestions?

Thanks in advance,

Corey
corey.hannum is offline   Reply With Quote
Old 15th February 2010, 23:09   #2
DrO
 
Join Date: Sep 2003
Posts: 27,873
not knowing all of the C# syntax, i'd suggest making sure that it's a pointer to the string you're passing and not the address of the buffer holding it. and also that it is an ansi encoded string (or change IPC_PLAYFILE to the unicode IPC_PLAYFILEW variant if it's a unicode string you're working with). other than that not too much else i can think off with my limited knowledge with C# (though how you've declared SendMessageA(..) but used SendMessage(..) is a bit baffling).

-daz
DrO is offline   Reply With Quote
Old 17th February 2010, 15:00   #3
corey.hannum
Junior Member
 
Join Date: Feb 2010
Posts: 2
I copied the code together from a few places in my source - thats why you see SendMessageA - copied from the wrong place.

Manged Code seems to make working with pointers much more complicated than it used to be. I'm going to look into whether the pointer is pointing to the string or buffer..

Anyone eles have any other suggestions??
corey.hannum is offline   Reply With Quote
Old 7th September 2020, 12:46   #4
aleksey_WinAmp
Junior Member
 
Join Date: Aug 2020
Posts: 6
Seems like this code works

code:

public class copy_data_4
{
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

[StructLayout(LayoutKind.Sequential)]
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}

public static uint WM_COPYDATA = 0x004A;

public static void send_string(string str_path, long l_comand, IntPtr i_hWnd)
{
IntPtr ptrCopyData = IntPtr.Zero;

// Create the data structure and fill with data
COPYDATASTRUCT copyData = new COPYDATASTRUCT();
copyData.dwData = new IntPtr(l_comand); // Just a number to identify the data type
copyData.cbData = str_path.Length + 1; // One extra byte for the \0 character
copyData.lpData = Marshal.StringToHGlobalAnsi(str_path);

// Allocate memory for the data and copy
ptrCopyData = Marshal.AllocCoTaskMem(Marshal.SizeOf(copyData));
Marshal.StructureToPtr(copyData, ptrCopyData, false);

// Send the message
SendMessage(i_hWnd, WM_COPYDATA, IntPtr.Zero, ptrCopyData);
}

}



code:

string str_path = "C:/my.mp3";

copy_data_4.send_string(str_path, (long)IPC_PLAYFILE, hWnd_WinAmp);

aleksey_WinAmp is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast 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