C++ String reaches over several NUL Bytes -
C++ String reaches over several NUL Bytes -
i hate inquire because think must trivial. used high-level-languages real problem.
i got c++ programme uses pdfium generate image pdf. , have c# programme communicates c++ programme via named pipes. pdf file (which saved byte-array) gets transmitted pipe. , here problem.
on 374th position of stream nul byte (00) , im stupid somehow reach info after it.
here code:
lptstr lpszpipename2 = text("\\\\.\\pipe\\mynamedpipe2"); hpipe2=createfile(lpszpipename2, generic_read, 0,null,open_existing,file_flag_overlapped,null); if(readfile( hpipe2, chbuf, dwbytestoread, &cbread, null)) { pdfdata = chbuf; }
dwbytes read size of file , cbread shows right number. pdfdata contains first 373 bytes. checked info beyond 373th position there immediate window don't know how process it. gotta set info char-array.
as said, think trivial. although know problem comes from, have no thought how prepare it.
many , regards
michael
edit: c#-code. perfect. i'm sure problem on c++ side.
public void sendrawdata(byte[] data) { while (clientse == null || clientse.stream == null) { } if (clientse.stream.canwrite) { clientse.stream.write(data, 0, data.length); clientse.stream.flush(); } } private void listenforclients() { while (true) { clienthandle = createnamedpipe(this.pipename, duplex | file_flag_overlapped, 0, 255, buffer_size, buffer_size, 0, intptr.zero); //could not create named pipe if (clienthandle.isinvalid) return; int success = connectnamedpipe(clienthandle, intptr.zero); //could not connect client if (success == 0) return; clientse = new client(); clientse.handle = clienthandle; clientse.stream = new filestream(clientse.handle, fileaccess.readwrite, buffer_size, true); if (clienttype == 0) { thread readthread = new thread(new threadstart(read)); readthread.start(); } } }
"solution": never real problem. got wires crossed. while chbuf seemed after copying pdfdata or when read value vs have 373 bytes. ~20 kilobytes copied position. knew that, didn't understand how pdfium sources should know if string terminates after 373 chars.
well... pdfium-sources know cause have pass length. determined
size_t len = pdfdata.length();
and hence of course of study 373 bytes.
the null character '\0'
used c/c++ terminate char*
strings. library function (i.e. strlen()
, strncpy()
, etc) utilize null character implicit end-of-string indicator. code doing somewhere. instead, utilize more memcpy()
or std::vector<char>
explicit info length.
c++ nul
Comments
Post a Comment