Search code examples
.netnamedpipeserverstream

using System.IO.Pipes.NamedPipeClientStream in a Sony Vegas Script


when i try to use a NamedPipeClientStream in a Sony Vegas Script i get the Exception

The type or namespace name 'NamedPipeClientStream' could not be found (are you missing   
a using directive or an assembly reference?)

and

The type or namespace name 'Pipe' could not be found in System.IO (are you missing     
a an assembly reference?)

this is what my code looks like:

new System.IO.Pipes.NamedPipeClientStream("UniqueString");

I have installed the latest .Net Framework (4.5) full. Where does Sony Vegas gets its assemblies.

Any suggestions?


Solution

  • The CLR hosted by Sony Vegas seems not to support NamedPipeClientStream. I achieved the same behaviour by using the Message System from Windows. Here is the Code i use in the Sony Vegas Script

    public static class SonyVegasWindowMessageHelper
    {
        private const int WM_USER = 0x400;
        private const int WM_COPYDATA = 0x4A;
        private const int VIDEO_RENDERED = 52;
    
        [DllImport("user32.dll")]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
        [DllImport("user32.dll", SetLastError = true)]
        private static extern bool SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
    
    
        public static void SendMessage(string message)
        {
            IntPtr window = FindWindow(null, "Youtube Video Uploader");
            if (window != IntPtr.Zero)
            {
                byte[] data = Encoding.Default.GetBytes(message);
    
                COPYDATASTRUCT str = new COPYDATASTRUCT();
                str.CbData = data.Length + 1;
                str.DwData = (IntPtr)VIDEO_RENDERED;
                str.LpData = message;
    
                SendMessage(window, WM_COPYDATA, IntPtr.Zero, ref str);
            }
        }
    
        private struct COPYDATASTRUCT
        {
            public IntPtr DwData;
            public int CbData;
    
            [MarshalAs(UnmanagedType.LPStr)]
            public string LpData;
        }
    }
    

    and with SendMessage you can send any message you want to an other application.