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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:22:10+00:00 2026-05-18T01:22:10+00:00

I am using the following code to create a file, but it always failed

  • 0

I am using the following code to create a file, but it always failed with error code 123 (the path syntax is not valid).

The strange thing is: path_ok is always ok, but path_err always failed with 123. And after the failure, the buffer that path_err points to is cleared.

Could anyone shed some light on me? I have checked the memory of the 2 pointers, and their contents seems to be identical.

Many thanks.

 WCHAR *pDumpFileName = ComposeDumpFileName();
 WCHAR *path_ok = _T("d:\\myapp_Utopia_2010-11-15_04-22-05.dmp");
 WCHAR *path_err = pDumpFileName;
 ::wprintf(pDumpFileName);
 HANDLE hFile = ::CreateFileW( pDumpFileName, GENERIC_READ | GENERIC_WRITE, 
  0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); 

The ComposeDumpFileName() function is like this:

WCHAR* ComposeDumpFileName(void)
{
 // get the time
    SYSTEMTIME sys_time;
    ::GetSystemTime(&sys_time);

    // get the computer name
    WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
    DWORD computer_name_len = ARRAYSIZE(computer_name);
 ::GetComputerNameW(computer_name, &computer_name_len);

    // build the filename: APPNAME_COMPUTERNAME_DATE_TIME.DMP
    WCHAR dump_file_path[MAX_PATH];

 ::swprintf_s(dump_file_path, ARRAYSIZE(dump_file_path), 
        _T("d:\\myapp_%s_%04u-%02u-%02u_%02u-%02u-%02u.dmp"), 
        computer_name, sys_time.wYear, sys_time.wMonth, sys_time.wDay,
        sys_time.wHour, sys_time.wMinute, sys_time.wSecond);

 return dump_file_path;
}

Update

In my above code, when I execute the following code:

WCHAR *pDumpFileName = ComposeDumpFileName();

After the ComposeDumpFileName returned, its stack frame is invalid, however, its local variable WCHAR dump_file_path[MAX_PATH] still exists on the stack. So this explains why I can still see its content though the stack space for it is invalid already.

Then I execute the following statement:

     ::wprintf(pDumpFileName);
     HANDLE hFile = ::CreateFileW( pDumpFileName, GENERIC_READ | GENERIC_WRITE, 
      0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); 

The wprintf() and CreateFileW() has their own stack frames. Though in the debugger, I found that wprintf()’s stack frame didn’t destroy the memory content pointed by the pDumpFileName, the CreateFileW could have, so it complains about a invalid path syntax.

This is my current understanding, please correct me if I am wrong.

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. Editorial Team
    Editorial Team
    2026-05-18T01:22:10+00:00Added an answer on May 18, 2026 at 1:22 am

    One major problem with your code is the buffer you are returning is on the stack and this is a big no no:

     // build the filename: APPNAME_COMPUTERNAME_DATE_TIME.DMP 
     WCHAR dump_file_path[MAX_PATH]; 
    

    Either change it to be a static:

     // build the filename: APPNAME_COMPUTERNAME_DATE_TIME.DMP 
     static WCHAR dump_file_path[MAX_PATH]; 
    

    or pass the buffer into the function.

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

Sidebar

Related Questions

No related questions found

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.