Click here to Skip to main content
15,919,245 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Tapi32.DLL weirdness Pin
Tim Deveaux13-Mar-02 10:46
Tim Deveaux13-Mar-02 10:46 
GeneralRe: Tapi32.DLL weirdness Pin
Michael P Butler13-Mar-02 12:30
Michael P Butler13-Mar-02 12:30 
GeneralRe: Tapi32.DLL weirdness Pin
#realJSOP14-Mar-02 0:05
professional#realJSOP14-Mar-02 0:05 
GeneralRe: Tapi32.DLL weirdness Pin
Nish Nishant13-Mar-02 13:07
sitebuilderNish Nishant13-Mar-02 13:07 
GeneralRe: Tapi32.DLL weirdness Pin
#realJSOP14-Mar-02 0:05
professional#realJSOP14-Mar-02 0:05 
GeneralPage eject Pin
ScottM13-Mar-02 8:29
ScottM13-Mar-02 8:29 
GeneralRe: Page eject Pin
Jason Hihn13-Mar-02 8:37
Jason Hihn13-Mar-02 8:37 
GeneralAnnoying ReadFile() problem Pin
Klaus Probst13-Mar-02 7:54
Klaus Probst13-Mar-02 7:54 
I have a simple WTL dialog-based app that uses a single thread to service a number of named pipe clients using overlapped (async) notification reads. When it receives a message from a connected client, the text is output to a RichEdit textbox (it's a sort of trace appy).

What I do is call PeekNamedPipe() to get the number of bytes queued in the pipe, then allocate a TCHAR of that size and use it as a buffer for ReadFile(). It works fine except for the fact that I always get trailing garbage chars on the buffer, even when I know that the message received, the number of bytes written to the pipe and the size of the read buffer are all exactly the same (I have a Unicode build that does the same thing). For the life of me I can't figure out what I'm doing wrong:

::PeekNamedPipe(thisPipe.hPipe,NULL,0,NULL,&dwBytesToRead, NULL);
if (dwBytesToRead !=0)
{
    try { 
	pData = new TCHAR[dwBytesToRead];
	memset((void*)pData,0,sizeof(TCHAR) * dwBytesToRead);
	dwBytesRead = 0;
    } catch(...) { return -1; }

}

fSuccess = ::ReadFile(thisPipe.hPipe,(LPVOID)pData,dwBytesToRead,&dwBytesRead,&thisPipe.ov);

if (fSuccess && (dwBytesRead != 0))
{ 
    pdlg->outputPipeWrite(pData);     // Write to the textbox

}


This is somewhat simplified code. The buffer is correctly delete[]'d after each receive. Basically, I can see the buffer being allocated and zeroed. When ReadFile() returns, I see the garbage chars at the end. I get no heap violations or anything like that, and I'm not leaking memory. It's bugging the heck out of me Smile | :)

The code that puts the text in the textbox is just a simple CRichEditCtrl::AppendText() call.

Thanks for any insight.


___________
Klaus
[www.vbbox.com]
GeneralRe: Annoying ReadFile() problem Pin
Klaus Probst13-Mar-02 8:09
Klaus Probst13-Mar-02 8:09 
GeneralRe: Annoying ReadFile() problem Pin
Tim Smith13-Mar-02 8:31
Tim Smith13-Mar-02 8:31 
GeneralRe: Annoying ReadFile() problem Pin
Klaus Probst13-Mar-02 16:00
Klaus Probst13-Mar-02 16:00 
QuestionVC++ Service Pack 5 Problem? Pin
Alexander Wiseman13-Mar-02 7:46
Alexander Wiseman13-Mar-02 7:46 
AnswerRe: VC++ Service Pack 5 Problem? Pin
Bill Wilson13-Mar-02 14:25
Bill Wilson13-Mar-02 14:25 
GeneralRe: VC++ Service Pack 5 Problem? Pin
Alexander Wiseman13-Mar-02 14:33
Alexander Wiseman13-Mar-02 14:33 
GeneralCreatewindow Pin
Anthony988713-Mar-02 7:30
Anthony988713-Mar-02 7:30 
GeneralRe: Createwindow Pin
Christian Graus13-Mar-02 9:39
protectorChristian Graus13-Mar-02 9:39 
GeneralRe: Createwindow Pin
alex.barylski13-Mar-02 15:08
alex.barylski13-Mar-02 15:08 
Generalaccuracy Pin
Rajveer13-Mar-02 7:11
Rajveer13-Mar-02 7:11 
GeneralRe: accuracy Pin
Joaquín M López Muñoz13-Mar-02 7:19
Joaquín M López Muñoz13-Mar-02 7:19 
GeneralRe: accuracy Pin
Ravi Bhavnani13-Mar-02 7:31
professionalRavi Bhavnani13-Mar-02 7:31 
GeneralRe: accuracy Pin
Tim Smith13-Mar-02 7:32
Tim Smith13-Mar-02 7:32 
GeneralRe: accuracy Pin
Klaus Probst13-Mar-02 16:06
Klaus Probst13-Mar-02 16:06 
GeneralULONGLONG Pin
Jon Hulatt13-Mar-02 6:49
Jon Hulatt13-Mar-02 6:49 
GeneralRe: ULONGLONG Pin
Tim Smith13-Mar-02 7:04
Tim Smith13-Mar-02 7:04 
GeneralPopup Static Window Pin
Anthony988713-Mar-02 5:54
Anthony988713-Mar-02 5:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.