CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Debugging problem

    Hi

    Im trying to debug a Win32 visual program because I have a "invalid pointer crash" but I cannot find it where because stepping over with F10 at a certain point debugging just stops and I cant step ahead anymore.

    It blocks at the end of the MainWndProc() loop.

    I dont understand why.

    Code:
    LRESULT CALLBACK MainWndProc(HWND hwnd,
        UINT uMsg,
        WPARAM wParam,
        LPARAM lParam)
    {
        HDC      hdc;
        PAINTSTRUCT  ps;
    
        switch (uMsg)
        {
        case WM_CREATE:
        {
    
            HINSTANCE dllhinst;
            HICON hIcon;
            HIMAGELIST himgList;
            InitCommonControls();
            himgList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
                GetSystemMetrics(SM_CYSMICON), ILC_COLOR32, 4, 4);
            ImageList_SetBkColor(himgList, GetSysColor(COLOR_WINDOW));
            dllhinst = LoadLibrary("shell32.dll");
    
            for (int i = 1; i<50; i++)
            {
                hIcon = LoadIcon(dllhinst, MAKEINTRESOURCE(i));
                ImageList_AddIcon(himgList, hIcon);
            }
    
            FreeLibrary(dllhinst);
    
            hTreeView =
                CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "",
                    WS_CHILD | WS_VISIBLE | TVS_HASLINES |
                    TVS_LINESATROOT | TVS_HASBUTTONS |
                    TVS_SHOWSELALWAYS,
                    0, 0, 190, 320,
                    hwnd, (HMENU)ID_TREEVIEW, hinst, NULL);
            TreeView_SetImageList(hTreeView, himgList, TVSIL_NORMAL);
    
            /// ///// LISTVIEW ////////////////
            int r = CreateListView(hwnd);
            if (r)
            {
                ReportError("CreateListView");
                return 0;
            }
    
            CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Button"), "Open",
                WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
                200, 10, 60, 25,
                hwnd, (HMENU)ID_OPEN, 0, NULL);
    
            // Create ComboBox
            hList = CreateWindow(TEXT("Combobox"),
                NULL, WS_CHILD | WS_VISIBLE |
                LBS_STANDARD,
                360, 10, 160, 325,
                hwnd, (HMENU)ID_LIST,
                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
                NULL);
    
            // Populate ComboBox
            FillComboBox(hList);
            /// populate treeview
            sSqliteFile =
                "C:\\Users\\Asus\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\rg6g9heo.default-1419956670839\\addons.sqlite";
            if (!LoadSqliteFile(0))  ReDrawTreeView(sSqliteFile);
    
            return 0;
        }
    
        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
            case ID_OPEN:
    
                if (!LoadSqliteFile(1))
                    ReDrawTreeView(sSqliteFile);
    
                break;
     
            }
            return 0;
    
        case WM_NOTIFY:
        {
            if (((LPNMHDR)lParam)->idFrom == ID_TREEVIEW)
            {
                if (((LPNMHDR)lParam)->code == NM_CLICK)
                {
    
                    /// TreeView_HitTest
                    /* Get the cursor position for this message */
                    DWORD dwPos = GetMessagePos();
                    POINT pt;
                    pt.x = GET_X_LPARAM(dwPos);
                    pt.y = GET_Y_LPARAM(dwPos);
                    //cout << " pt: " << pt.x <<" " << pt.y << endl;
                    TVHITTESTINFO lpht = { 0 };
                    ScreenToClient(hTreeView, &pt);
                    lpht.pt = pt;
    
                    TreeView_HitTest(hTreeView, &lpht); //
                                                        //cout << " text: " << lpht.hItem << endl;
                    if (lpht.hItem)
                        GetTextItemTree(lpht.hItem, sCurrentTable);
    
               
    
                    /// redraw listwiew with new info
                    if (sCurrentTable != sSqliteFile)
                    {
                        if (!Get_Table_Info(sCurrentTable))
                        {
                            SendMessage(hList, CB_RESETCONTENT, 0, 0);
                            FillComboBox(hList);
                            SendMessage(hList, CB_SETCURSEL, 0, 0);
                            RemoveListViewColumns();
                            AddListViewColumns();
                      
                            std::thread Column_Info_Thread(Get_Column_Info);
    
                            Column_Info_Thread.detach();
    
            
                        }
                    }
                }
            }
        }
        return 0;
    
        case WM_PAINT:
        {
            hdc = BeginPaint(hwnd, &ps);
            TextOut(hdc, 290, 15, "Columns:", 8);
            EndPaint(hwnd, &ps);
        }
        return 0;
    
        case WM_CLOSE:
            DestroyWindow(hwnd);
            return 0;
    
        case WM_DESTROY:
            DisonnectDB();
            PostQuitMessage(0);
            return 0;
    
        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
        }
    } ---> it blocks here
    

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Debugging problem

    try to look at the Call stack window...
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Debugging problem

    Thank you Victor, the Call stack window shows:

    > user32.dll!_InternalCallWinProc@20() Unknown


    Call before: VisualStudioDebug.exe!MainWndProc(HWND__ * hwnd, unsigned int uMsg, unsigned int wParam, long lParam) Line 244 C++

    Call after: user32.dll!_UserCallWinProcCheckWow@32() Unknown

  4. #4
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Debugging problem

    OK, the crash is occurring in the "void Get_Column_Info()" function that I call by the thread "std::thread Column_Info_Thread(Get_Column_Info);".

    But when I try to step into this thread by F11 to get to the function it only enters the thread but not the function.

    What am I doing wrong?

  5. #5
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: Debugging problem

    OK, I found out how to debug threads.
    Last edited by MasterDucky; September 13th, 2015 at 03:36 AM.

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