C# using SendMessage, problem with WM_COPYDATA

前端 未结 3 2024
甜味超标
甜味超标 2020-12-18 04:15

I\'ve been spending a few days (or more) trying to get this to work.

The application at hand is FTPRush, and I know there is a cmd line application call

3条回答
  •  Happy的楠姐
    2020-12-18 05:08

    My Definitions have

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
    public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
    
    public struct COPYDATASTRUCT {
      public int cbData;
      public IntPtr dwData;
      [MarshalAs(UnmanagedType.LPStr)] public string lpData;
    }
    
    var cds = new Win32.COPYDATASTRUCT {
                                               dwData = new IntPtr(3),
                                               cbData = str.Length + 1,
                                               lpData = str
                                             };
    Win32.SendMessage(ftprush, Win32.WM_COPYDATA, IntPtr.Zero, ref cds);
    

    Of course, make sure that str is null terminated "\0"

    Alternatively a definition given by PInvoke.NET is

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, StringBuilder lParam);
    //If you use '[Out] StringBuilder', initialize the string builder with proper length first.
    

提交回复
热议问题