2012-12-19 43 views
0

當我嘗試使用NamedPipeClientStream在索尼拉斯維加斯的腳本中,我得到異常在索尼拉斯維加斯使用System.IO.Pipes.NamedPipeClientStream腳本

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

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

這是什麼我的代碼如下所示:

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

我已經安裝了最新的.Net Framework(4.5)。索尼拉斯維加斯在哪裏得到它的組裝

有什麼建議嗎?

回答

0

Sony Vegas託管的CLR似乎不支持NamedPipeClientStream。我通過使用Windows的消息系統實現了相同的行爲。這裏是我在索尼拉斯維加斯腳本中使用的代碼

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; 
    } 
} 

並且使用SendMessage,您可以將任何消息發送給其他應用程序。

1

那麼,這是接近我的牀,我已經在索尼拉斯維加斯工作,並知道它的CLR託管方案相當不錯。您遇到此問題是因爲System.IO.Pipes是.NET 4名稱空間,Vegas中的自定義CLR主機加載CLR 2.0.50727版本。

您可以覆蓋該選項,您可以編輯Program Files文件夾中的.exe.config文件,並使用<supportedRuntime>元素來加載v4版本。不知道你會遇到什麼樣的麻煩,它不是一個經過測試或支持的方案。

下一個最接近的選擇是使用Socket來代替。由於您只需要選擇一個端口號,因此通常比WM_COPYDATA更容易實現。獲得窗口句柄可能會很棘手,FindWindow()不是一個非常可靠的函數。