CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 1999
    Posts
    85

    Unhandled Exceptions different in 64bit? / vs2008

    I have a program that works fine in 32bit mode on vs6.

    but in 2008 64bit it sometimes gets an unhandled exception crash in the following code (PostMessage line):-

    Is something different in 64bit vs2008? error is: Access violation reading location


    if(wnd && ::IsWindow(wnd->m_hWnd))
    {
    try
    {
    wnd->PostMessage(WM_COMMAND,MAKELONG(0x01,BN_CLICKED),(LPARAM)(wnd->GetDlgItem(0x01))->m_hWnd); // post ok to message
    }
    catch(...)
    {

    // do nothing
    }
    }
    Last edited by hobnob; February 5th, 2013 at 07:32 AM.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Unhandled Exceptions different in 64bit? / vs2008

    Quote Originally Posted by hobnob View Post
    I have a program that works fine in 32bit mode on vs6.
    After 80 posts and no code tags?
    but in 2008 64bit it sometimes gets an unhandled exception crash in the following code (PostMessage line):-
    That line just assumes that wnd->GetDlgItem(0x01) returns a valid pointer.

    Regardless of the OS, you should be checking all of your pointers are not NULL before you use them.
    Code:
    if(wnd && ::IsWindow(wnd->m_hWnd))
    This does not guarantee that the wnd is a valid instance.

    It could very well be that wnd is an invalid pointer value which isn't NULL, and the contents of wnd->m_hWnd just by luck happens to be a valid window handle. Then you go and use the junk pointer in the call to wnd->PostMessage.

    So you have two holes in the code you're showing, and again, regardless of the OS, should be rectified.

    Regards,

    Paul McKenzie

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured