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 8999859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:14:08+00:00 2026-06-16T00:14:08+00:00

The following code is causing grief when run from Studio 2010 debugger, but seems

  • 0

The following code is causing grief when run from Studio 2010 debugger, but seems to run fine from the command line (well, it would because the exception is only thrown in the debugger):

HANDLE hCon = GetStdHandle( STD_OUTPUT_HANDLE );  // Preserve STDOUT
HANDLE hFile = CreateFile( pszOutputFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
// At this point hFile = 0x000000d0
// The file is created and has 0 bytes, as expected

// STDOUT is redirected to our new file handle
SetStdHandle( STD_OUTPUT_HANDLE, hFile );

// Do something here that pumps to STDOUT, output is directed to the file correctly
CloseHandle( hFile );  // EXCEPTION here: 0xC0000008: An invalid handle was specified.
SetStdHandle( STD_OUTPUT_HANDLE, hCon );  

A simple CreateFile/CloseHandle sequence works fine, and I have also tried switching the order of the CloseHandle/SetStdHandle calls to no avail, but GetLastError does return 18 (0x12) ERROR_NO_MORE_FILES “There are no more files.” if SetStdHandle does run.

Something with the STDOUT redirection is failing, but what?

  • 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. Editorial Team
    Editorial Team
    2026-06-16T00:14:09+00:00Added an answer on June 16, 2026 at 12:14 am

    So, it seems the problem was caused by this section, cunningly hidden by the code’s original author:

       int fd = _open_osfhandle( (intptr_t)hFile, O_WRONLY | O_TEXT );
       _dup2( fd, 1 );
    //   _close( fd );
    

    The _close, here commented out, seems to cause the problem.

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

Sidebar

Related Questions

The following code is causing me some problems. The third line causes a program
The following line of code is causing me an Exception using (new INVU.API.CallContextStore()) {
The following line of code is causing me an Exception plug.Instance.AddDocuments(new Int32[] { val_pid
This post concerns only IE. The last line of the following code is causing
Basically the following code is causing your problem: $(sourceImageForm).find('.imagef1_upload_process').css('visibility','hidden'); $(sourceImageForm).find('.imagef1_cancel').css('visibility','hidden'); /// THIS LINE BELOW
The following code in my function (run in a loop) is causing my program
The following code works, but am I running the risk of causing circular reference
I am trying to run PhotoStream sample from following link http://android-developers.blogspot.com/2008/09/android-photostream.html But when i
The following code does not have any errors when run script.py -f filename but
The following code is causing this error: if (bestLine.size() > searchDepth - depth) bestLine.erase(bestLine.begin(),

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.