c++ - 如何将管道句柄转换为 Google protobuf 的 file_descriptor(int)

标签 c++ handle protocol-buffers

我尝试按照示例 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/

相关文章:

protocol-buffers - 在protobuf-c中表示指针变量

c++ - 在模板类中初始化 C++ 数组成员

jquery方式的Javascript继承

java - 在输出文件中找不到 protobuf 服务

c++ - C++ 中的句柄、空指针、对象

jquery 可排序处理 IE 与 Firefox

c++ - Protobuf ShortDebugString() 崩溃

c++ - 在 C++11 中同步整个类

c++ - 使用 foreach 循环连续迭代两个结构的简单方法

c++ - 不可复制类型的 std::initializer_list 替代品