Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 150699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:19:55+00:00 2026-05-11T09:19:55+00:00

I have a Win32 application that I’m making, and it sends a string from

  • 0

I have a Win32 application that I’m making, and it sends a string from one process to another via a named pipe. However, the process that calls ReadFile on the pipe gets the string with some garbled data in it. It returns the number of bytes written correctly, but the last 8 characters or so of the string are garbled.

Here is the code for creating the pipe, and writing to it:

myPipe = CreateNamedPipe(L'\\\\.\\pipe\\testpipe', PIPE_ACCESS_OUTBOUND, PIPE_NOWAIT, 10, 512, 512, 10, NULL); TCHAR title[128]; GetWindowText(foundHwnd, title, 128); wstring windowTitle(title); vector<wstring> splitVec; boost::split(splitVec, windowTitle, boost::algorithm::is_any_of(wstring(L'|'))); WriteFile(myPipe, splitVec[0].c_str(), splitVec[0].size(), &wrote, NULL); 

And here is the code that reads it:

if (WaitNamedPipe(L'\\\\.\\pipe\\testpipe', 5000) == 0) {     MessageBox(NULL, L'Unable to wait for pipe', L'Error', MB_OK);     return false; }  myPipe = CreateFile(L'\\\\.\\pipe\\testpipe', GENERIC_READ, FILE_SHARE_READ, NULL,     OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (myPipe == INVALID_HANDLE_VALUE) {     MessageBox(NULL, L'Unable to open pipe', L'Error', MB_OK);     return false; }     // Other code here...     TCHAR buf[512];     DWORD read;     success = ReadFile(myPipe, buf, 512, &read, NULL);     if (read > 0)         MessageBox(NULL, buf, L'Got Data', MB_OK); 

When MessageBox is shown, the end of the string is garbled and I have no idea why. Any ideas?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:19:55+00:00Added an answer on May 11, 2026 at 9:19 am

    I think the key here is to make sure that your strings are null terminated and that you send the termination character as well. You shouldn’t have to send the entire buffer if the communications is synchronous or if you set it up in PIPE_READMODE_MESSAGE. ReadFile will return when either the specified number of bytes has been read or a write operation completes on the other end of the pipe. I believe that the ‘garbled’ text is really garbage in the read buffer on the client side of the pipe and because you are not transmitting the string termination character, it is including this in the text sent to the message box. Either clear your read buffer before sending or send the string termination character with the message and I think it will work without the overhead of sending a full buffer.

    Here is sample client from MSDN. Note how the client sends exactly the number of characters in the message + 1 (including the termination character) and receives into a fixed buffer of size 512. If you look at a server example, you’ll see the same pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think you could replace the \n\n with (\r?\n){2} this… May 11, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer Try setting the wmode parameter to transparent swfobject.embedSWF("open-flash-chart.swf", "Dashboard_Chart","800", "400",… May 11, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer If inheriting doesn't work out, you could also use jQuery… May 11, 2026 at 11:40 pm

Related Questions

I have a Win32 application that I'm making, and it sends a string from
I have a delphi (Win32) web application that can run either as a CGI
I have a system tray icon that receives incoming phone calls. When a call
I have a Win32 GUI application that has several edit controls (plain old EDIT
I'm working on a C++ project that I don't intend to develop or deploy

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.