popup menus & its massage handling

i've crerated a floting popup menu which its items are getting to a popup menus as well. when i compile the program in a debug mode everything works well, but when i compile it in a release mode i get an access violation message. i guess that the problem is somehow related to message routing.
 thanks for any help!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi matid,

I once had the same problem with a popup menu within a modeless dialog. I could not solve the problem directly, only found a workaround:

CMyDialog::OnContextMenu(CWnd* pWnd, CPoint point)
 CMenu menu;
 // create/load menu
 UINT cmd = ::TrackPopupMenu( hMenu, TPM_RETURNCMD, point.x, point.y, 0, pWnd->m_hWnd, 0 );
 if ( cmd != 0 )
  // successfully selected an item
  pWnd->SendMessage( WM_COMMAND, MAKELONG( cmd, 0 ), NULL );

hope that helps,

It will be easier to find the problem if u send the code on how u are creating the popup menu. One way of debugging such problems is to comment out certain chunk of code and see if the crash still occurs. For example, comment out OnContextMenu and if the release version works, then u have to look into OnContextMenu.
You need to debug your application. We can't do it for you.  If you want us to do it for you, you'll need to send along a lot more information!

As outside guesses, you might've made a mistake in declaring a message handler. Or, you might have abused the ASSERT() macro.

..B ekiM

When getting the handle of the Menu or Window donot simply get the owner. Use the functions

1> GetSafeHwnd() while getting HWND pointer.
2> GetSafeHmenu() while getting HMENU pointer
3> GetSafeHandle() while getting HGDIOBJ pointer.

The cause is invalid parent pointers.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
> The cause is invalid parent pointers.

It is?  Why would they be valid in a debug build and not in a release build?

..B ekiM
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.