The code below is snippet of a code in my application whose goal is to get item data from a listbox.
for (int j = 0; j <; iSelected; j++)
{
long long llCustomerID = SendMessage
(GetDlgItem(hDlg, IDC_LIST1), LB_GETITEMDATA, pSelected[j], 0);
vTransactions.push_back(llCustomerID);
}
The item data has been set in this manner:
int iPos = SendMessage(GetDlgItem(hDlg, IDC_LIST1), LB_GETCURSEL, 0, 0);
SendMessage(GetDlgItem(hDlg, IDC_LIST1), LB_SETITEMDATA, iPos, (LPARAM)llCustomerID);
Memory was allocated to the smart pointer as shown below:
unique_ptr<int []> pSelected = make_unique<int []>(iSelCount);
Where,
iSelCount
is the number of selections made in the
listbox
as returned by
LB_GETSELCOUNT
message.
The problem is that
llCustomerID
receives
1
, instead of the database value of the transaction which should be
25
. The numeral
1
received happens to be the ID of the first transanctions listed in the
lisbox
which was never selected.
Where exactly have I missed it?
The code below shows how values were assigned to
pSelected
:
int iSelected = SendMessage(GetDlgItem(hDlg, IDC_LIST1), LB_GETSELITEMS, iSelCount, (LPARAM)pSelected.get());
What I have tried:
I have spent quality time trying to debug, but am yet to get any desired outcome.