MFC based C++ program assert failed

win*_*ton 2 c++ debugging mfc assert target-platform

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:

在目标机器上运行调试版本而发布版本正常时断言消息

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)

调试版本的依赖项遍历器结果

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

当我将其部署到目标机器时,发布版本运行正常,但调试版本失败。即使我安装了vc_redist.x64.exe(从我的开发机器复制),并处理了相关的mfc140d.dll,msvcp140d.dll,vcruntime140d.dll和vcruntime140_1d.dll。实际上,我将所有以下文件复制到目标计算机的同一目标目录下:

将文件复制到目标机器同一目录下

谁能告诉我出了什么问题吗?我不知道从哪里调试它。

多谢。

sel*_*bie 5

我认为 Dependency Walker 对于您的需求不是很有用。断言对话框意味着程序已成功启动,但遇到意外状态。因此,您已经满足了所有运行时依赖项。

我机器上的 afxwin2.inl 第 795 行是这样的:

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

基本上,有一个断言窗口上的控件(组合框)仍然有效。也许某些代码在窗口关闭后仍在尝试执行某些操作。

所有这些都是解决方案。

  • 在目标计算机上安装 Visual Studio。直接在其上构建和调试。

  • 安装远程调试工具。这是在无法本地重现的情况下进行调试的标准方法。将其与远程桌面相结合,以便您可以单击远程计算机上的对话框并在本地计算机上进行调试。

  • 更手动的解决方案是将所有 PDB 文件复制到与其相应的 EXE 或 DLL 相同的目录中(例如,将 foo.pdb 放在与 foo.exe 相同的目录中,但将 bar.pdb 放在与 bar.dll 相同的目录中) , ETC...)。然后使用可以复制到目标计算机的工具(例如WinDbg) 。然后调试。还要设置您的源路径。