-
June 21st, 2012, 03:13 PM
#1
ShellExecute crashes Dev Studio 2008 SP 1
I have a MFC Dialog based application, and when I get a certain user-defined windows message I do the following:
ShellExecute(NULL,NULL,(const char*)WLC.Settings.FinishURL, NULL,NULL,SW_SHOW);
That FinishURL is just a basic CString. Anyway, this causes Dev Studio 2008 to crash. I can rum my app stand alone by going into the build folder and running the debug or release version and it runs just fine.
I know this is a long shot, but does anyone know why this is crashing Dev Studio 2008 and how I can fix it? I have since added some #ifndef DEBUG around it, but I would rather it actually execute while I am testing.
-
June 21st, 2012, 03:43 PM
#2
Re: ShellExecute crashes Dev Studio 2008 SP 1
I have no idea, but FWIW, you don't need to cast a CString to a const char*. It has an overloaded operator for that.
Are you saying VIsual Studio itself is crashing, or your app is crashing inside the debugger?
-
June 21st, 2012, 03:43 PM
#3
Re: ShellExecute crashes Dev Studio 2008 SP 1
Could you give us some more information? Like what kind of 'crash' are you getting and what the call stack looks like? Have you tried debugging to see if any of the variables contain garbage data when making the call?
Last edited by Access_Denied; June 21st, 2012 at 03:46 PM.
-
June 21st, 2012, 04:15 PM
#4
Re: ShellExecute crashes Dev Studio 2008 SP 1
Dev Studio is crashing. Not my application. I can't look at the call stack because the development environment crashes.
-
June 22nd, 2012, 03:33 AM
#5
Re: ShellExecute crashes Dev Studio 2008 SP 1
Originally Posted by DeepT
Dev Studio is crashing. Not my application. I can't look at the call stack because the development environment crashes.
Do you mind to explain what is Dev Studio? Is it Visual Studio? Or something else?
Best regards,
Igor
-
June 21st, 2012, 03:44 PM
#6
Re: ShellExecute crashes Dev Studio 2008 SP 1
- Is it so hard to use Code tags and white spaces between the argument list? Doesn't it look better:
Code:
ShellExecute(NULL, NULL, (const char*)WLC.Settings.FinishURL, NULL, NULL, SW_SHOW);
- What is the purpose to cast "CString" to const char* type?
- Is your build causing the crash an ANSI or UNICODE?
- How does the message handler look like?
- What exactly does this CString contain?
- Do you by chance make some GetBuffer without the following ReleaseBuffer?
Victor Nijegorodov
-
June 21st, 2012, 04:19 PM
#7
Re: ShellExecute crashes Dev Studio 2008 SP 1
2. To make sure I get the char * type of pointer. CString does this with a cast. I just want to make sure I end up with a pointer to a buffer of *char and not a reference to an object.
3. I am using ANSI, the build works fine, the app runs until it hits that statement then Dev Studio crashes. Not my App, but the development environment.
4. Message Handler hook?
5. It constains, "https://www.google.com". You can launch URLs this way and it will use the default system web browser.
6. No.
-
June 21st, 2012, 04:31 PM
#8
Re: ShellExecute crashes Dev Studio 2008 SP 1
Originally Posted by DeepT
2. To make sure I get the char * type of pointer. CString does this with a cast. I just want to make sure I end up with a pointer to a buffer of *char and not a reference to an object.
Then, please, read the post from GCDEF.
Did you try to rebuild your project, ... to delete .ncb, .opt, .aps and so on files?
To restart Windows?
Victor Nijegorodov
-
June 21st, 2012, 07:48 PM
#9
Re: ShellExecute crashes Dev Studio 2008 SP 1
Originally Posted by DeepT
5. It contains, "https://www.google.com". You can launch URLs this way and it will use the default system web browser.
We can't see what's behind those variables, so do this -- hardcode into the call of ShellExecute that string. Does it crash then?
Or even do this -- declare a CString right before the call and set it to the string:
Code:
CString whatever = "https://www.google.com";
ShellExecute(... whatever, ...);
If these do not crash, then the suspicion is that you've corrupted the CString object in some way, or the CString doesn't contain the string you say it contains. If the "whatever" version crashes, then there still is a suspicion of corruption (since CString uses reference counting).
I can rum my app stand alone by going into the build folder and running the debug or release version and it runs just fine
Means very little, seriously. Many buggy app can "run fine" when run under one circumstances, but when run under the debugger, or another computer, then all heck breaks loose. C++ isn't Java or C#, where if you make a mistake, you're guaranteed some sort of diagnostic to be produced.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; June 21st, 2012 at 07:51 PM.
-
June 22nd, 2012, 08:28 AM
#10
Re: ShellExecute crashes Dev Studio 2008 SP 1
I am Visual Studio 2008.
I tried this:
Code:
CString URL = "https://www.google.com";
ShellExecute(NULL,NULL,(const char*)URL, NULL,NULL,SW_SHOW);
and this also crashes Visual Studio 2008. Putting in the string directly in place of the CString works without a crash.
However, even this:
Code:
CString URL = "https://www.google.com";
char *str = (char *)(const char *)URL;
ShellExecute(NULL,NULL,str, NULL,NULL,SW_SHOW);
Crashes Visual Studio 2008. I put a break point into the call and str does point at the correct string.
-
June 22nd, 2012, 08:42 AM
#11
Re: ShellExecute crashes Dev Studio 2008 SP 1
Originally Posted by DeepT
I am Visual Studio 2008.
I tried this:
Code:
CString URL = "https://www.google.com";
ShellExecute(NULL,NULL,(const char*)URL, NULL,NULL,SW_SHOW);
and this also crashes Visual Studio 2008. Putting in the string directly in place of the CString works without a crash.
If the build is Unicode, those casts are incorrect. As a matter of fact, why are you doing all of those C-style casts to begin with?
Any time I see casting all over the place like that, it gives the indication that the code would never have compiled unless you forced the compiler to keep quiet by casting. So to be honest with you, I am not surprised the call crashes or the string being pointed to is not correct.
The ShellExecute function takes LPCTSTR as the string parameters, not const char*. This very simple example should have worked:
Code:
LPCTSTR URL = _T("https://www.google.com");
ShellExecute(NULL,NULL, URL, NULL,NULL,SW_SHOW);
Notice the _T() macro?
Then create a brand new program, and just these two lines:
Code:
CString URL = _T("https://www.google.com");
ShellExecute(NULL,NULL, (LPCTSTR)URL, NULL,NULL,SW_SHOW);
The reason why you should try this with an untouched, new program is because CString can get corrupted due to it being a reference counted type. If you've messed up the reference counting in some way, then all bets are off.
Regards,
Paul McKenzie
-
June 22nd, 2012, 08:47 AM
#12
Re: ShellExecute crashes Dev Studio 2008 SP 1
Seriously, stop casting CStrings to const char*. Here's why you don't need to.
http://msdn.microsoft.com/en-us/libr...=vs.60%29.aspx
I know that's not the problem here, but it's an unnecessary habit you should get out of.
-
June 22nd, 2012, 08:50 AM
#13
Re: ShellExecute crashes Dev Studio 2008 SP 1
I'd also try to replace the second NULL with the _T("open") verb.
Victor Nijegorodov
-
June 22nd, 2012, 09:02 AM
#14
Re: ShellExecute crashes Dev Studio 2008 SP 1
Ok, this code block also crashes Dev Studio 2008 and has nothing to do with CStrings:
Code:
#define URL "https://www.google.com"
int Len = strlen(URL);
char Buff[1024] = {0};
CopyMemory( &Buff[0], URL, Len );
ShellExecute(NULL,_T("open"),Buff, NULL,NULL,SW_SHOW);
-
June 22nd, 2012, 09:22 AM
#15
Re: ShellExecute crashes Dev Studio 2008 SP 1
Originally Posted by DeepT
Ok, this code block also crashes Dev Studio 2008 and has nothing to do with CStrings:
Code:
#define URL "https://www.google.com"
int Len = strlen(URL);
char Buff[1024] = {0};
CopyMemory( &Buff[0], URL, Len );
ShellExecute(NULL,_T("open"),Buff, NULL,NULL,SW_SHOW);
This code is wrong!
Please, try what Paul suggested:
Originally Posted by Paul McKenzie
Then create a brand new program, and just these two lines:
Code:
CString URL = _T("https://www.google.com");
ShellExecute(NULL,NULL, (LPCTSTR)URL, NULL,NULL,SW_SHOW);
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|