]> git.saurik.com Git - wxWidgets.git/commitdiff
Add error checking when retrieving client data from wxMSW wxListBox.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 20 Jan 2012 22:11:44 +0000 (22:11 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 20 Jan 2012 22:11:44 +0000 (22:11 +0000)
Verify if retrieving client data failed which might happen if the index
is invalid for example. This makes code more robust and also consistent with
wxChoice.

Closes #13883.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70415 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/listbox.cpp

index 69565096f7b90a0fd9dc8c3cea7892829375b4fc..fd17da4b4177f57c1f995954b38b48d646106ec2 100644 (file)
@@ -306,7 +306,15 @@ bool wxListBox::IsSelected(int N) const
 
 void *wxListBox::DoGetItemClientData(unsigned int n) const
 {
-    return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA, n, 0);
+    LPARAM rc = SendMessage(GetHwnd(), LB_GETITEMDATA, n, 0);
+    if ( rc == LB_ERR && GetLastError() != ERROR_SUCCESS )
+    {
+        wxLogLastError(wxT("LB_GETITEMDATA"));
+
+        return NULL;
+    }
+
+    return (void *)rc;
 }
 
 void wxListBox::DoSetItemClientData(unsigned int n, void *clientData)