简体   繁体   English

Visual Studio C ++控制台应用程序无法运行

[英]Visual Studio C++ Console Application Won't Run

What can be done when a C++ console application builds and launches but won't run any code, at least not any that the debugger can see? 当C ++控制台应用程序生成并启动但不运行任何代码(至少没有调试器可以看到的任何代码)时,该怎么办? I have a program with a main function: 我有一个具有主要功能的程序:

int main (int argc, char *argv[])
{
    short retval = 0;
    retval = samain ( (short) argc, argv);
    return ((int) retval);
}

I put a breakpoint on the first line ( retval=0 ) and the line after it just to be safe, and run. 为了安全起见,我在第一行( retval=0 )及其后的行上放置了一个断点,然后运行。 It shows a console window and hangs until I stop the debugger. 它显示一个控制台窗口并挂起,直到停止调试器。 The debug output shows a number of DLLs being loaded but nothing else. 调试输出显示了许多正在加载的DLL,但没有其他内容。 It ends with this line that looks very similar to the dozens before it: 它的结尾与之前的数十行非常相似:

'fcmtsysmd.exe' (Win32): Loaded 'C:\Windows\SysWOW64\RpcRtRemote.dll'. Cannot find or open the PDB file.

This is a program I know runs and functions in a "normal" environment because hundreds of people are using it and I haven't changed the code. 我知道这是一个程序,可以在“正常”环境中运行并运行,因为数百人正在使用它,而我没有更改代码。 The things different in my environment (because I'm in the process of rewriting our installation process) are: 我的环境中的不同之处(因为我正在重写安装过程中)是:

  1. I might not have all the dependencies installed properly. 我可能没有正确安装所有依赖项。
  2. One of the DLL dependencies that was causing an error earlier has been replaced by a newly built version with an Isolated COM reference instead of its usual COM reference because the COM object it was trying to access is not registered. 之前导致错误的DLL依赖项之一已被带有隔离COM引用而不是其通常的COM引用的新建版本替换,因为它尝试访问的COM对象未注册。 (I'm trying to implement isolated COM in our new installation.) (我正在尝试在我们的新安装中实现隔离的COM。)

So my question is, if an error is occurring before the first line of code executed, how can I track down the source of the problem? 所以我的问题是,如果在执行第一行代码之前发生错误,我该如何追踪问题的根源?

I can't get a sensible call stack because even if I single step (F10 key) to start the program, it's hung right away. 我无法获得明智的调用堆栈,因为即使我单步执行(F10键)以启动程序,该程序也会立即挂起。 If I break at that point, I see the following call stack: 如果此时中断,则会看到以下调用堆栈:

ntdll.dll!7743fdd1()    Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] 
ntdll.dll!7743fdd1()    Unknown
ntdll.dll!77475f86()    Unknown
ntdll.dll!77459809()    Unknown

When I remove the isolated COM settings from the dependent DLL, I can get a access violation exception and stop on some code in the debugger. 当我从依赖的DLL中删除隔离的COM设置时,我可以获取访问冲突异常并在调试器中停止某些代码。 It's stopped on a function being called during the initialization of a static variable in another DLL. 在另一个DLL中的静态变量初始化期间被调用的函数上停止了该操作。 The strange thing is, when I add the isolated COM settings to the first DLL, and put a breakpoint on the other DLL, the breakpoint doesn't even get hit. 奇怪的是,当我将隔离的COM设置添加到第一个DLL,并在另一个DLL上放置一个断点时,该断点甚至都没有命中。

It turns out that the application was hanging during a call to CoCreateInstance triggered by some static initialization logic in one of the dependent DLLs. 事实证明,在依赖于其中一个DLL的某些静态初始化逻辑触发的对CoCreateInstance的调用期间,该应用程序已挂起。 I guess the trick is trying to identify static initialization logic in dependent DLLs and putting breakpoints there. 我猜想诀窍是试图在依赖的DLL中识别静态初始化逻辑,并在其中放置断点。 Unfortunately there doesn't appear to be any debug output to help identify which DLL's static initialization is executing when, so it's impossible to tell which DLL is the problem. 不幸的是,似乎没有任何调试输出可帮助识别哪个DLL的静态初始化在何时执行,因此无法确定哪个DLL是问题所在。

I will ask about how to identify the source of a hanging CoCreateInstance call in a separate question if there isn't already a question covering it: Application hung during CoCreateInstance when using Isolated COM 我将在一个单独的问题中询问有关如何识别挂起的CoCreateInstance调用的源的问题,如果还没有覆盖它的问题: 使用隔离COM时在CoCreateInstance期间应用程序挂起

The final answer ended up being at https://stackoverflow.com/a/34076433/78162 (which I had to create myself). 最终的答案是在https://stackoverflow.com/a/34076433/78162 (我必须自己创建)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C ++ Visual Studio无法完全运行程序 - C++ Visual Studio Won't fully run program Visual C ++应用程序无法在Windows 7上运行 - Visual C++ application won't run on windows 7 Visual C ++窗体应用程序将无法在其他计算机上运行 - Visual C++ Forms Application won't run on other computers 无法在Visual Studio 2013中创建C ++控制台应用程序 - Can't create C++ console application in Visual Studio 2013 是否可以在Linux下的Mono中运行在Visual Studio 2013中编译的Win 32控制台C ++应用程序? - Can win 32 console C++ application compiled in Visual Studio 2013 be run in Mono under Linux? 为什么我的简单C ++控制台应用程序在Visual Studio 2015中看不到我的简单C ++静态库标头? - Why won't my simple C++ console app see my simple C++ static library headers in Visual Studio 2015? 在Visual Studio 2012中对C ++控制台应用程序进行单元测试 - Unit testing c++ console application in Visual Studio 2012 Visual Studio 2022 for mac 无法创建 c++ 控制台应用程序 - visual studio 2022 for mac cannot create c++ console application Visual Studio C ++ 2010如何将ICON添加到控制台应用程序 - Visual Studio C++ 2010 How to add an ICON to a console application C ++-Qt-Visual Studio 2010-具有GUI和控制台的应用程序 - C++ - Qt - Visual Studio 2010 - application with both gui and console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM