![](/img/trans.png)
[英]How do I use a Win32 Class Library in a Win32 Application in Visual Studio 2010 Express?
[英]How to use win32 pipe on single application
我正在嘗試寫入我在本地創建的管道(在同一應用程序中)
目前,我有這個:
audioPipe = CreateNamedPipe(
L"\\\\.\\pipe\\audioPipe", // name of the pipe
PIPE_ACCESS_OUTBOUND, // 1-way pipe -- send only
PIPE_TYPE_MESSAGE, // send data as a byte stream
1, // only allow 1 instance of this pipe
0, // no outbound buffer
0, // no inbound buffer
0, // use default wait time
NULL // use default security attributes
);
我不知道如何實際向其中寫入數據。 我猜想使用WriteFile()
但是還有更多嗎? 我閱讀的所有示例似乎都在使用客戶端服務器系統,而我並不需要。 我只需要將數據寫入管道(希望ffmpeg接管)
基於注釋,您正在創建命令行FFMPEG應用程序將連接到的命名管道。 為了使其正常工作,您需要做三件事:
將您對CreateNamedPipe()
調用更改為使用PIPE_TYPE_BYTE
而不是PIPE_TYPE_MESSAGE
,因為您將把原始數據實時流傳輸到FFMPEG,而不是消息。 這將允許FFMPEG使用它想要的任何任意緩沖區等從管道讀取數據,就好像它是直接從真實文件中讀取一樣。
audioPipe = CreateNamedPipe( L"\\\\\\\\.\\\\pipe\\\\audioPipe", // name of the pipe PIPE_ACCESS_OUTBOUND, // 1-way pipe -- send only PIPE_TYPE_BYTE, // send data as a byte stream 1, // only allow 1 instance of this pipe 0, // no outbound buffer 0, // no inbound buffer 0, // use default wait time NULL // use default security attributes );
您需要先調用ConnectNamedPipe()
以接受來自FFMPEG的連接,然后才能向其中寫入數據。
ConnectNamedPipe(audioPipe, NULL);
運行FFMPEG時,請使用-i
參數將管道名稱指定為輸入文件名,例如: ffmpeg -i \\\\.\\pipe\\audioPipe
。
除了調用WriteFile
之外,沒有什么比這更多的了。 在調用WriteFile
等待客戶端連接之前,您還需要調用ConnectNamedPipe
。
客戶端通過使用CreateFile
打開句柄,然后使用ReadFile
讀取管道中的內容。
對於字節流,您需要PIPE_TYPE_BYTE
。 您確定要將緩沖區大小指定為0嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.