-
June 22nd, 2012, 09:14 AM
#16
Re: ShellExecute crashes Dev Studio 2008 SP 1
No, i didn't try that in an application by itself. It is final step in my other app. I could paste that into a new app. If it crashes or does not, what does that tell me? Note this is crashing the development environment. My application, if you run it outside of the development environment runs just fine and launches the URL correctly. I want to know why this call causes my development environment to crash.
Ok, I just created a new MFC Dialog based project. On Init dialog I put that code (in my last post). It ran fine and did not crash Dev Studio 2008.
-
June 22nd, 2012, 09:22 AM
#17
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
-
June 22nd, 2012, 09:26 AM
#18
Re: ShellExecute crashes Dev Studio 2008 SP 1
Ok, VictornN, I tried that exact code you pasted and it crashes Dev Studio 2008 in my project.
This code:
Code:
CString URL = _T("https://www.google.com");
ShellExecute(NULL,NULL, (LPCTSTR)URL, NULL,NULL,SW_SHOW);
-
June 22nd, 2012, 09:43 AM
#19
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:
That code is wrong if it's a Unicode app.
Not only should you get out of the habit of casting, get into the habit of using _T(), TEXT(), TCHAR, etc. instead of char, char*, etc. Also, your "CopyMemory" would be wrong, since CopyMemory takes the number of bytes, not the number of characters. A Unicode app has 2-byte characters, not 1 byte.
I know you say you're using ANSI, but mistakes like this gives the impression you may be making mistakes in other places in your app, causing memory corruption in some way.,
Code:
TCHAR Buff[1024] = _T("https://www.google.com");
ShellExecute(NULL,_T("open"),Buff, NULL,NULL,SW_SHOW);
This code should work, regardless of the build type.
Regards,
Paul McKenzie
-
June 22nd, 2012, 09:49 AM
#20
Re: ShellExecute crashes Dev Studio 2008 SP 1
It is not unicode. Anyway Ill just put the debug macros around it and not execute it in my development environment. My app runs just fine when run stand-alone.
-
June 22nd, 2012, 09:57 AM
#21
Re: ShellExecute crashes Dev Studio 2008 SP 1
Originally Posted by DeepT
Anyway Ill just put the debug macros around it and not execute it in my development environment. My app runs just fine when run stand-alone.
That is not a fix. If your app ran great on one computer and flunked out on another, do you throw the computer away where your application fails, so as to "fix the bug" and say "it works on my main machine, so it's OK"? Honestly, that "fix" you came up with would be totally unacceptable in a professional environment.
As I stated previously, if a C++ application has a bug, there is no guarantee how it will run. You need to figure out exactly why mysteriously your CStrings are corrupted. If a simple ShellExecute of a web address were so buggy, then it would have been reported by hundreds if not thousands of programmers.
Regards,
Paul McKenzie
-
June 22nd, 2012, 10:05 AM
#22
Re: ShellExecute crashes Dev Studio 2008 SP 1
Remember it's not his app that's crashing, it's Visual Studio. Nothing in his code should be able to cause that. It is possible that there's nothing wrong with his code at all.
-
December 8th, 2012, 04:38 AM
#23
Re: ShellExecute crashes Dev Studio 2008 SP 1
I have the same thing happening. Nothing to do with the code, it's Visual Studio bug.
Nikita Leontiev
Just Manager Developer
-
December 8th, 2012, 03:48 PM
#24
Re: ShellExecute crashes Dev Studio 2008 SP 1
strlen does not include the the null-termination so your copy wont be null-terminated. See http://msdn.microsoft.com/en-us/library/78zh94ax.aspx
Edit: Sorry, I didnt account for your init
Last edited by S_M_A; December 10th, 2012 at 04:32 PM.
-
December 10th, 2014, 12:09 PM
#25
Re: ShellExecute crashes Dev Studio 2008 SP 1
(Two years later...)
I was having this problem, too, but I solved it by making the following change.
From this:
Code:
CFile htmFile;
CString strFileName = _T("C:\\Temp\\TempHTML.htm");
if ( htmFile.Open(strFileName, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite )
{
// Write stuff to the file
...
htmFile.Flush(); // I put the Flush in as a test to see if it would help, but it didn't. I left it in anyway.
htmFile.Close();
::ShellExecute(NULL, _T("open"), strFileName, NULL, NULL, SW_SHOW); // VS crashes here in Debug only
}
To this:
Code:
CFile htmFile;
CString strFileName = _T("C:\\Temp\\TempHTML.htm");
BOOL rc = htmFile.Open(strFileName.GetBuffer(), CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite);
strFileName.ReleaseBuffer();
if ( rc )
{
// Write stuff to the file
...
htmFile.Flush();
htmFile.Close();
::ShellExecute(NULL, _T("open"), strFileName, NULL, NULL, SW_SHOW); // This works in Debug & Release
}
Apparently, CFile::Open must be holding onto something vital in the CString.
Last edited by yooper; December 10th, 2014 at 12:12 PM.
Reason: Highlighting
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
|