我尝试按照示例 here 使用句柄 hPipe
:
hPipe = CreateNamedPipe(
lpszPipename, // pipe name
PIPE_ACCESS_DUPLEX, // read/write access
PIPE_TYPE_MESSAGE | // message type pipe
PIPE_READMODE_MESSAGE | // message-read mode
PIPE_WAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // max. instances
BUFSIZE, // output buffer size
BUFSIZE, // input buffer size
0, // client time-out
NULL);
ZeroCopyOutputStream* raw_output = new FileOutputStream(hPipe);
CodedOutputStream* coded_output = new CodedOutputStream(raw_output);
但是报错:
'google::protobuf::io::FileOutputStream::FileOutputStream(int,int)' : cannot convert parameter 1 from 'HANDLE' to 'int'
这是签名:
FileOutputStream(int file_descriptor, int block_size = -1);
那么如何在 C++ 中将句柄转换为 file_descriptor?
更新
我尝试了推荐的 _open_osfhandle
但似乎不正确,报告:
error C2664: '_open_osfhandle' : cannot convert parameter 1 from 'HANDLE' to 'intptr_t'
最佳答案
听起来你想要的是_open_osfhandle
.
关于c++ - 如何将管道句柄转换为 Google protobuf 的 file_descriptor(int),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3576726/