MFC: "failed to create empty document" error shown for non English language

Narayanaswamy, Suresh 1 Reputation point
2021-01-25T08:20:15.743+00:00

Hi Experts,

We have a legacy MFC SDI application which is ~15year old. Currently it is getting built using VC14 runtime. Recently we noticed one issue where the application started failing to launch with error dialog "failed to create empty document". Application only fails to load when the UI language is non-English. I have checked and ensured there are no changes done from past 1 year to this code base.

This is where the error dialog comes from:

The CWinApp child class <MyApplication>App class's InitInstance() ProcessShellCommand(cmdInfo) shows "failed to create empty document" error and application fails to launch in Japanese and Chinese languages and it works fine with English.

Edit:
Some more info after Jeanine inputs:

Thank you for the detailed explanation Jeanine.
With the help of your answer, I further debugged the code and isolated the problem area. Following is the flow in working condition and failure.

Q_DISMAINFRAME_CLASS::PreCreateWindow seems to be getting called twice in a normal case where as in a failure case, Q_DISMAINFRAME_CLASS::PreCreateWindow is not getting called the second time. I made sure that the code related to this app is not changed between last working version and now. Isolating the system software environment is a huge task knowing my MFC limited knowledge.

Any help is much appreciated.

Failed case: System language set to Dutch
P_GENUI_WINAPP_CLASS::InitInstance() start
cmd_line_param_ptr: (null)
Before calling ProcessShellCommand
Q_DISDOC_CLASS::Q_DISDOC_CLASS() start
before configure
After configure()
Q_DISDATABUFFER_CLASS::Q_DISDATABUFFER_CLASS start
Q_DISDATABUFFER_CLASS::Q_DISDATABUFFER_CLASS end
Q_DISDOC_CLASS::Q_DISDOC_CLASS() exit
P_GENUI__FRAME_BASE_CLASS::STACKING_ORDER_STRUCT::STACKING_ORDER_STRUCT()
P_GENUI__FRAME_BASE_CLASS::P_GENUI__FRAME_BASE_CLASS() start
P_GENUI__FRAME_BASE_CLASS::retrieve_stacking_order() start
P_GENUI__FRAME_BASE_CLASS::retrieve_stacking_order() end
ERROR_SUCCESS == ret_val : 1
P_GENUI__FRAME_BASE_CLASS::P_GENUI__FRAME_BASE_CLASS() end
Q_DISMAINFRAME_CLASS::Q_DISMAINFRAME_CLASS()
Q_DISMAINFRAME_CLASS::PreCreateWindow start
P_GENUI__FRAME_BASE_CLASS::set_createstruct
P_GENUI__FRAME_BASE_CLASS::set_createstruct - success: 1
lpszClass: AfxFrameOrView140u
lpszName: (null)
cx: -2147483648
cy: -2147483648
wExStyle: 512
style: 0
x: 0
y: 0
Q_DISMAINFRAME_CLASS::PreCreateWindow end
return_value: 1

I get "Failed to create empty document" error here

Working case : System language set to EN
P_GENUI_WINAPP_CLASS::InitInstance() start
cmd_line_param_ptr: (null)
Before calling ProcessShellCommand
Q_DISDOC_CLASS::Q_DISDOC_CLASS() start
before configure
After configure()
Q_DISDATABUFFER_CLASS::Q_DISDATABUFFER_CLASS start
Q_DISDATABUFFER_CLASS::Q_DISDATABUFFER_CLASS end
Q_DISDOC_CLASS::Q_DISDOC_CLASS() exit
P_GENUI__FRAME_BASE_CLASS::STACKING_ORDER_STRUCT::STACKING_ORDER_STR
P_GENUI__FRAME_BASE_CLASS::P_GENUI__FRAME_BASE_CLASS() start
P_GENUI__FRAME_BASE_CLASS::retrieve_stacking_order() start
P_GENUI__FRAME_BASE_CLASS::retrieve_stacking_order() end
ERROR_SUCCESS == ret_val : 1
P_GENUI__FRAME_BASE_CLASS::P_GENUI__FRAME_BASE_CLASS() end
Q_DISMAINFRAME_CLASS::Q_DISMAINFRAME_CLASS()
Q_DISMAINFRAME_CLASS::PreCreateWindow start
P_GENUI__FRAME_BASE_CLASS::set_createstruct
P_GENUI__FRAME_BASE_CLASS::set_createstruct - success: 1
lpszClass: AfxFrameOrView140u
lpszName: (null)
cx: -2147483648
cy: -2147483648
wExStyle: 512
style: 0
x: 0
y: 0
Q_DISMAINFRAME_CLASS::PreCreateWindow end
return_value: 1
Q_DISMAINFRAME_CLASS::PreCreateWindow start
P_GENUI__FRAME_BASE_CLASS::set_createstruct
P_GENUI__FRAME_BASE_CLASS::set_createstruct - success: 1
lpszClass: Afx:00F00000:b:00010003:00000006:00010643
lpszName: DisplayApp
cx: -2147483648
cy: -2147483648
wExStyle: 512
style: 0
x: -2147483648
y: -2147483648
Q_DISMAINFRAME_CLASS::PreCreateWindow end
return_value: 1
Q_DISMAINFRAME_CLASS::OnCreate start
Q_DISSIGNAL_COMBI_BOX_CLASS::Q_DISSIGNAL_COMBI_BOX_CLASS() start
Q_DISSIGNAL_COMBI_BOX_CLASS::Q_DISSIGNAL_COMBI_BOX_CLASS() end
Q_DISDVIEW_CLASS::Q_DISDVIEW_CLASS() start
Q_DISDVIEW_CLASS::Q_DISDVIEW_CLASS() exit
Q_DISMAINFRAME_CLASS::OnCreate end
Q_DISDVIEW_CLASS::OnInitialUpdate()
Q_DISDVIEW_CLASS::DoDataExchange start
Q_DISDVIEW_CLASS::DoDataExchange end

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,562 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 9,266 Reputation points Microsoft Vendor
    2021-01-26T03:32:53.73+00:00

    Hi,

    When CCommandLineInfo cmdInfo is defined, the constructor is called first, and m_nShellCommand is set to FileNew in the constructor. Then execute ParseCommandLine(cmdInfo); analyze the command. Finally execute ProcessShellCommand (cmdInfo), ProcessShellCommand () judges m_nShellCommand as FileNew, and then calls OnFileNew()

    CWinApp::OnFileNew implements this command differently depending on the number of document templates in the application.

    Both CDocTemplate::CreateNewDocument and CDocTemplate::CreateNewFrame will cause this prompt if they fail. If there is no error in the program, unless there is insufficient memory, CDocTemplate::CreateNewDocument is unlikely to fail.

    The LoadFrame() in CreateNewFrame() which is the source of this "Failed to create new document" error. As long as it returns False, such a prompt will pop up. LoadFrame() calls CFrameWnd::Create() to create a window, and if it fails to create a window, Fasle is returned.

    According to the above analysis, we can get:

    1 If the menu resource cannot be found, return False and also pop up "Failed to create empty document"
    2 Overloading PreCreateWindow and returning False will also cause a pop-up "Failed to create empty document"
    3 Returning -1 in OnCreate will also cause a pop-up "Failed to create empty document".

    Best Regards,

    Jeanine


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Jim Faes 0 Reputation points
    2023-08-15T13:59:58.85+00:00

    I ran into the same issue on a C++ VS 2019 project. The code work fine for all of our US based PCs. When I released the application in Germany I got the same error. I got around the issue with the following code:

    	if (!ProcessShellCommand(cmdInfo))
    		{
    			if (!ProcessShellCommand(cmdInfo))
    			{
    				return FALSE;
    			}
    		}
    
    
    0 comments No comments