__targv 在我的 MFC Windows 应用程序中为 NULL。参数== 1
我有一个 Windows 应用程序设置如下: 调试 - 构建一个静态链接它使用的库的 exe 发布 - 构建一个链接到 DLL 的 exe
我刚刚创建了发布版本,唯一的区别是所使用的库之一现在被构建为 DLL。
当我执行我的应用程序时,每当访问命令行参数时,它都会崩溃。这是由于 __targv 为 NULL,而 argc == 1。
以前有人遇到过这种情况吗?
I have a windows application setup as follows:
Debug - builds an exe which statically links the libraries it uses
Release - builds an exe which links to a DLL
I've just created the release version, the only difference being is that one of the libraries that is used, is now being built as a DLL.
When I execute my application, whenever the command line arguments are accessed it crashes. This is due to __targv being NULL, yet argc == 1.
Has anyone come across this before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
__targv 中的第一个参数是当前可执行文件的路径和名称。
这就是为什么参数计数为 1。尝试在屏幕上打印
__targv[0]
的内容,您应该看到类似C:/.../.../foobar 的内容。 exe
(其中.../...
是可执行文件的路径,foobar.exe
是 exe)The first parameter in __targv is the path and name of the current executable.
This is why the argument count is at 1. Try printing on screen the content of
__targv[0]
, you should see something likeC:/.../.../foobar.exe
(where.../...
is the path to your executable andfoobar.exe
being the exe)感谢大家的建议和帮助。
如果有人感兴趣,这里有一些问题的解决方案。另外,如果其他人遇到过这个问题,这就是为他们准备的:
在创建 DLL 的过程中,我必须将 C 运行时库切换为 MD(DLL 类型)和(我认为)MFC 链接配置(UseOfMFC)。
我错误地混合了 UseOfMFC 类型,我认为这会弄乱 _targv 并在调用任何 AFX 函数时导致异常。
我重新访问了该项目,将所有配置更改为使用 DLL 类型 CRT,并保持 UseOfMFC 不变。这解决了我遇到的问题。
Thanks to everyone for the suggestions and help.
If anyone is interested, here is some closure to the problem. Also, if anyone else ever has this problem, this is for them:
In the processing of creating the DLL, I had to switch the C runtime library to MD (DLL type) and (I thought) MFC linking configuration (UseOfMFC).
I had mistakenly mixed UseOfMFC types, which I believe was messing up _targv as well as causing exceptions when calling any AFX functions.
I revisited the project, changing all configurations to using the DLL type CRT and left the UseOfMFC untouched. This fixed the problems I was having.