ShellExecute crashes Dev Studio 2008 SP 1 - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24

Thread: ShellExecute crashes Dev Studio 2008 SP 1

  1. #16
    Join Date
    Sep 2004
    Posts
    1,361

    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.

  2. #17
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,418

    Re: ShellExecute crashes Dev Studio 2008 SP 1

    Quote Originally Posted by DeepT View Post
    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:
    Quote Originally Posted by Paul McKenzie View Post
    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

  3. #18
    Join Date
    Sep 2004
    Posts
    1,361

    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);

  4. #19
    Join Date
    Apr 1999
    Posts
    27,429

    Re: ShellExecute crashes Dev Studio 2008 SP 1

    Quote Originally Posted by DeepT View Post
    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

  5. #20
    Join Date
    Sep 2004
    Posts
    1,361

    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.

  6. #21
    Join Date
    Apr 1999
    Posts
    27,429

    Re: ShellExecute crashes Dev Studio 2008 SP 1

    Quote Originally Posted by DeepT View Post
    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

  7. #22
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,107

    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.

  8. #23
    Join Date
    Dec 2012
    Posts
    1

    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

  9. #24
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,634

    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 03:32 PM.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center