views:

56

answers:

1

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'
+1  A: 

It sounds like what you want is _open_osfhandle.

Jerry Coffin
Which header files do I need to include besides `io.h`? Now it's reporting `_O_TEXT` in `_open_osfhandle(hPipe, _O_TEXT);` as undefined..
It sounds like you also need `#include <fcntl.h>`.
Jerry Coffin
Seems `_open_osfhandle` is not the right one, now it's reporting `error C2664: _open_osfhandle : cannot convert parameter 1 from HANDLE to intptr_t`
Yes, you do have to use a cast -- in this case, it's normal and harmless (and, though not what I'd call a particularly wonderful design for the function).
Jerry Coffin
I'm interested how to cast it?
wamp
@wamp: Something like: `_open_osfhandle((intptr_t)handle, _O_WHATEVER);`
Jerry Coffin
Is there any library that I should link to? I'm met with this error now: `unresolved external symbol CodedOutputStream@io@protobuf@google`