Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tough release problem 1

Status
Not open for further replies.

Simse

Programmer
Feb 24, 2005
22
Hi there,
i think, i have quite a tough problem:
in my program i have a hotkey in order to hide or show stuff. in debug-mode it works just fine, but when i release the program, it crashes the SECOND(!) time i hit the hotkey. the error message says something like: "the instruction in "0x6c27....." refers to memory in "0x0...033a". "read" process could not be executed on memory." (it is displayed twice)
the debugger only shows some opcode. now, when i un-comment (is this the right word?) the code inside OnHoyKey(), the problem is still there, when leave the function out completely, the program at least doesn't crash anymore.
here some lines of code that might be relevant:

// in OnInitDialog()
BOOL bRetCode = RegisterHotKey(GetSafeHwnd(),1,MOD_ALT|MOD_SHIFT,'X');
ASSERT(bRetCode);

//in OnHotKey()
bReadOnly=!bReadOnly;
LabelMode->ShowWindow(bReadOnly);
etc...

i have no clue what to do. please help me, thanks
 
The code sample you posted is not enough to tell. Here are some suggestions:
(1) Make sure all ASSERT(...) blocks refer to the code that is not required in Release version, since they will be omitted. If you need it in Release use VERIFY(...) instead;
(2) In your particular case check if LabelMode is a valid pointer and how you declare it, but again it's hard to say at this stage. Probably it's a static (global?) variable that is initialized only once and if you run the same code fragment the second time it somehow corrupts the memory.
(3) Use BoundsChecker if you want to spend an extra buck -- it's very handy for finding all memory leaks, overlapping and the like.
 
Hi,

I know it's very few code but i can't figure out what else to post because these are the only lines having anything to do with my OnHotKey()-routine!
(1) I replaced the only ASSERT in my code by VERIFY, nothing changed...
(2) LabelMode is just an example of my code, it's certainly not the problem. As i wrote earlier, i can leave all the code in OnHotKey() out, the error is still there...
(3) Thanks for the hint, i'll try it if i can't get to any other solution!
Maybe some code again:

//ON_MESSAGE(WM_HOTKEY,OnHotKey)
...
/*void CMemcalcSheet::OnHotKey()
{...}*/
No effect, no crash. Clearly!

ON_MESSAGE(WM_HOTKEY,OnHotKey)
...
void CMemcalcSheet::OnHotKey()
{ /*...*/ }
No effect but crash.

What REALLY perplexes me is the fact that the crash occurs after the second time the HotKey is hit. After the first time, everything runs usually!
 
Well, I'm not sure what the problem is. It might be some latent memory leak that grows with each iteration and then crashes the program when you press your hot key the second time (these ones are hardest to find). BoundsCHecker can help you find it. Google for it, check their web site. Maybe they have a trial version so you won't have to pay for it.

As I come to think about it, make sure you declare OnHotKey like this (You might've made mistake in its declaration since its handler is not supplied by MFC):

afx_msg LRESULT OnHotKey(WPARAM wParam, LPARAM lParam);
LRESULT CMyHotKeyDlg::OnHotKey(WPARAM wParam, LPARAM lParam)
{
return 0;
}

I have a sample of how I would employ a hot key for an MFC dialog box but I can't find the way to attach it here. PM me or let me know your email and I will send it to you if info above doesn't help.

Cheers...
 
Yeeeeehah!

:) Thank you very much, dc2000, it worked!!! Finally, I'm happy! ;-)
Have a nice day, bye!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top