Quantcast
Channel: CodeGuru Forums - C++ and WinAPI
Viewing all articles
Browse latest Browse all 583

Debugging problem

$
0
0
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


Viewing all articles
Browse latest Browse all 583

Trending Articles