Announcement

Collapse
No announcement yet.

SendMessage Enque Song in Playlist

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • thinktink
    replied
    Just so you know, I am not familiar with C#, just C++ so what I have to point out might be inapplicable.

    However:

    I noticed the provided function doesn't appear to explicitly free the allocated memory for storing the struct information passed to Winamp in the SendMessage and the memory allocated by "Marshal.AllocCoTaskMem" which MSDN says must be deallocated with "Marshal.FreeCoTaskMem(IntPtr)". From my understanding of Winamp API, both can be safely deallocated/freed after the call to SendMessage returns.

    Leave a comment:


  • meltor
    replied
    Very cool.

    Leave a comment:


  • aleksey_WinAmp
    replied
    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);

    Leave a comment:


  • corey.hannum
    replied
    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??

    Leave a comment:


  • DrO
    replied
    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

    Leave a comment:


  • corey.hannum
    started a topic SendMessage Enque Song in Playlist

    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
Working...
X
😀
🥰
🤢
😎
😡
👍
👎