• Welcome to Valhalla Legends Archive.
 

ShellExecute

Started by brew, July 21, 2007, 12:12 PM

Previous topic - Next topic

brew

So um... after successfully opening the folder, the program works great, just as planned. then when i try to close it, my program crashes. you know, the laggy kind, with the "this application has encountered an error and needs to close" sort of thing. It works perfectly fine in VB6, i don't get why this is happening in C++.

case ID_OPEN_FOLDER:
    char path[256];
    // GetModuleFileName(NULL, buf, 256); //was going to use this...
    GetCurrentDirectory(256, path);
    ShellExecute(hwnd, NULL, path, NULL, "C:\\", 1);
    break;

....

case WM_CLOSE:
    FreeLibrary(hRichtxt);
    DestroyWindow(hwnd);
    break;
case WM_DESTROY:
    PostQuitMessage(0);
    break;

you see?
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Kp

At what line does the crash occur?
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

brew

Quote from: Kp on July 21, 2007, 11:24 PM
At what line does the crash occur?

To be honest, I have absolutely no idea. When i run it with the debugger, it just runs in the main GetMesssage() loop and I never get a chance to close the window manually, but when I put SendMessage(hwnd, WM_CLOSE, 0, 0); in the WM_CREATE handler it seems to give me an unhandled exception, access violation. (at the line where i create the window).
When I run the program as normal, it gives me the " a problem has encountered " dialog, and i press debug, it gives me another error. this time an "application error" which basically says "The instruction at memoryaddresshere referenced memory at randomaddresshere. The memory could not be "read"." So basically I have no way to find exactly what line it crashes on..
However when I don't call FreeLibrary(); to free the rich text box's library it doesn't close at all. By the way, now (after doing nothing different) it starts crashing after i close it all the time....
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

l2k-Shadow

put MessageBox(0, "test#", "0", 0); after each one of your lines around where you suspect the crash is and you can pinpoint the problem.

such random crashes are probably due to you corrupting memory somewhere, look through your project and make sure you are allocating/freeing memory appropriately.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Kp

Quote from: brew on July 21, 2007, 11:59 PM
Quote from: Kp on July 21, 2007, 11:24 PM
At what line does the crash occur?

To be honest, I have absolutely no idea. When i run it with the debugger, it just runs in the main GetMesssage() loop and I never get a chance to close the window manually, but when I put SendMessage(hwnd, WM_CLOSE, 0, 0); in the WM_CREATE handler it seems to give me an unhandled exception, access violation. (at the line where i create the window).
When I run the program as normal, it gives me the " a problem has encountered " dialog, and i press debug, it gives me another error. this time an "application error" which basically says "The instruction at memoryaddresshere referenced memory at randomaddresshere. The memory could not be "read"." So basically I have no way to find exactly what line it crashes on..
However when I don't call FreeLibrary(); to free the rich text box's library it doesn't close at all. By the way, now (after doing nothing different) it starts crashing after i close it all the time....

That memory address should be all you need.  Attach a debugger to the process and disassemble that address.  If you have symbols set up correctly, it should tell you the function name and, if it is in your code, the file and line number that map to that address.

What do you mean it "just runs in the main GetMessage() loop"?  Is the debugger breaking in?  If not, in what way is the program behaving differently when the debugger is present versus when it is absent?

Your remark about FreeLibrary implies that you may be unloading the richtext control while it is still in use.  Destroy all the richtext windows before you free the richtext library.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

brew

Quote from: Kp on July 29, 2007, 08:03 PM
Quote from: brew on July 21, 2007, 11:59 PM
Quote from: Kp on July 21, 2007, 11:24 PM
At what line does the crash occur?

To be honest, I have absolutely no idea. When i run it with the debugger, it just runs in the main GetMesssage() loop and I never get a chance to close the window manually, but when I put SendMessage(hwnd, WM_CLOSE, 0, 0); in the WM_CREATE handler it seems to give me an unhandled exception, access violation. (at the line where i create the window).
When I run the program as normal, it gives me the " a problem has encountered " dialog, and i press debug, it gives me another error. this time an "application error" which basically says "The instruction at memoryaddresshere referenced memory at randomaddresshere. The memory could not be "read"." So basically I have no way to find exactly what line it crashes on..
However when I don't call FreeLibrary(); to free the rich text box's library it doesn't close at all. By the way, now (after doing nothing different) it starts crashing after i close it all the time....

That memory address should be all you need.  Attach a debugger to the process and disassemble that address.  If you have symbols set up correctly, it should tell you the function name and, if it is in your code, the file and line number that map to that address.

What do you mean it "just runs in the main GetMessage() loop"?  Is the debugger breaking in?  If not, in what way is the program behaving differently when the debugger is present versus when it is absent?
Yes that's what I ment, I didn't really know how to phrase it because I never really worked with debuggers, what I ment is that it never broke in unless it receives a window message and stops executing so i am unable to do the events which send the appropriate window messages.... but that's not really a problem because whatever piece of code i want to single step in, i would just have it run on WM_CREATE (although that's not a permanent solution).

Quote
Your remark about FreeLibrary implies that you may be unloading the richtext control while it is still in use.  Destroy all the richtext windows before you free the richtext library.
Thanks, Kp. I destroyed the rich text box before unloading the library, and it all works perfectly now.
Also, would it have the same effect if I called DestoryWindow (for the main window) before unloading the dll?
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Kp

If I recall correctly, DestroyWindow will destroy child windows as well.  If it destroys the child windows before execution reaches the FreeLibrary call, you will be fine.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!