MFC based C++ program assert failed

173 Views Asked by At

I wrote a MFC based C++ program, while the release version runs smoothly on the target machine, the debug version can not. it appears assert failed as the following screenshot shows:

assert message when running debug version on target machine while release version ok

I need this debug version to run on the target machine, so I can remote debug it by attaching to it from my developing machine.

I use the new version of dependency walker (https://github.com/lucasg/Dependencies), but it gives same result as the release one (no red alart), even though release version can run, the debug version can not. the dependency walker show the following:(the second screenshot)

dependency walker result for the  debug version

because in my developing machine which installed visual studio 2022 (mfc 143), it runs ok both for debug version and release version.

while when I deploy it to the target machine, the release version runs ok, but the debug version failed. even I installed vc_redist.x64.exe (copyed from my developing machine), and coped the relative mfc140d.dll ,msvcp140d.dll, vcruntime140d.dll and vcruntime140_1d.dll. actually, I copied all the folling files to the target machine under the same target directory:

the files copied to the target machine under same directory

could any one show me what's wrong? I don't know where to debug it from.

thanks a lot.

1

There are 1 best solutions below

0
selbie On

I don't think Dependency Walker is very useful for what you need. The Assert dialog implies the program is successfully starting, but hitting an unexpected state. Hence, you've got all the runtime dependencies satisfied.

Line 795 of afxwin2.inl on my machine is this:

_AFXWIN_INLINE int CComboBox::AddString(LPCTSTR lpszString)
    { ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, CB_ADDSTRING, 0, (LPARAM)lpszString); }

Basically, there's an assert that the control (combo box) on the window is still valid. Perhaps some code is still attempting to do something after the window was closed.

All of these are solutions.

  • Install Visual Studio on the target machine. Build and debug directly on that.

  • Install the remote debugging tools. This is the standard way to debug where you can't repro locally. Combo this with remote desktop so you can click through the dialogs on the remote machine and debug on the local machine.

  • A more manual solution would be to copy over all the PDB files to the same directory as its corresponding EXE or DLL (e.g. put foo.pdb in the same directory as foo.exe, but bar.pdb in the same dir as bar.dll, etc...). Then use a tool such as WinDbg that can be xcopy'd over to the target machine. Then debug. Set your source path as well.