0

I do not understand the following situation:

    HWND hListView = CreateWindowEx( 0, WC_LISTVIEW, NULL, WS_CHILD | WS_VISIBLE |
                                   LVS_REPORT | LVS_EDITLABELS | LVS_SHOWSELALWAYS, 0,
                                   0, rcl.right - rcl.left, rcl.bottom - rcl.top,
                               hMain,( HMENU ) 1000, inst, NULL);
    int error = GetLastError();//error=0;
    //ListView is displayed correctly
    //Some Code for columns
    //Now trying to enable grouping via SendMessage or following macro returns error:6?
    //What the...
    ListView_EnableGroupView(hListView, TRUE);
    error = GetLastError();//error=6;ERROR_INVALID_HANDLE
    //Some Code for Items

So what am i missing ;D ? It's hilarious to get this error while the handle is right there above, working for other things (columns, rows/items)

Edit_1 - 7:27(GMT): Yep, its always error 6 whenever its placed after creating columns/items/groups and all kinds of combinations, here is the code:

    //Groups - Send-Recv
LVGROUP lvg;
lvg.cbSize = sizeof(LVGROUP);
lvg.mask = LVGF_HEADER | LVGF_GROUPID;

lvg.pszHeader = L"Gr1";
lvg.iGroupId = 1;
ListView_InsertGroup( hListView, - 1, & lvg );
//MessageBoxA(NULL, i2s(GetLastError()).c_str(), "ERROR2", MB_OK | MB_ICONERROR);
lvg.pszHeader = L"Gr2";
lvg.iGroupId = 2;
ListView_InsertGroup( hListView, - 1, & lvg );
    //Enable
ListView_EnableGroupView(hListView, TRUE);
//error 6
user1017258
  • 53
  • 2
  • 6

1 Answers1

3

Only ever call GetLastError() when you got a failure return code from the Windows api function and the documentation tells you that the api function sets the last error.

Neither is the case here for your usage of ListView_EnableGroupView().

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Agreed. `ListView_EnableGroupView()` returns its own error code directly if it fails, it does not use `GetLastError()`. – Remy Lebeau Sep 24 '12 at 02:57