View Single Post
Old 7th September 2020, 11: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