__targv is NULL in my MFC windows application. argc == 1
I have a windows application setup as follows: Debug - builds an exe which statica开发者_如何学Clly 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?
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 like C:/.../.../foobar.exe
(where .../...
is the path to your executable and foobar.exe
being the exe)
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.
精彩评论