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

发布于 2024-09-16 06:53:36 字数 1344 浏览 3 评论 0原文

我尝试按照示例 这里

  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'

I tried to use the handle hPipe as following the example here:

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

But get an error:

'google::protobuf::io::FileOutputStream::FileOutputStream(int,int)' : cannot convert parameter 1 from 'HANDLE' to 'int'

And here's the signature:

FileOutputStream(int file_descriptor, int block_size = -1);

So how to convert a handle to file_descriptor in c++?

UPDATE

I tried the recommended _open_osfhandle but seems not correct, reporting:

error C2664: '_open_osfhandle' : cannot convert parameter 1 from 'HANDLE' to 'intptr_t'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谈下烟灰 2024-09-23 06:53:36

听起来您想要的是 _open_osfhandle

It sounds like what you want is _open_osfhandle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文