Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

Well, that's close to my bed, I've worked on Sony Vegas and know its CLR hosting scenario pretty well. You have this problem because System.IO.Pipes is a .NET 4 namespace, the custom CLR host in Vegas loads CLR version 2.0.50727.

You can override that choice, you can edit the .exe.config file in Program Files folder and use the <supportedRuntime> element to get the v4 version loaded. Not sure what kind of trouble you'll run into doing this, it is not otherwise a tested or supported scenario.

The next closest alternative is to use a Socket instead. Usually easier to get going than WM_COPYDATA since you only need to select a port number. Getting the window handle can be tricky, FindWindow() isn't a very reliable function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top