Click here to Skip to main content
15,914,392 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem handling WM_NCPAINT using XP visual style Pin
khb21-Jul-03 20:33
khb21-Jul-03 20:33 
GeneralMultiple modal dialog boxes Pin
Deepak Samuel21-Jul-03 7:11
Deepak Samuel21-Jul-03 7:11 
Generala casting problem! Pin
safee ullah21-Jul-03 7:11
safee ullah21-Jul-03 7:11 
GeneralRe: a casting problem! Pin
Dominik Reichl21-Jul-03 7:19
Dominik Reichl21-Jul-03 7:19 
GeneralRe: a casting problem! Pin
Joaquín M López Muñoz21-Jul-03 7:28
Joaquín M López Muñoz21-Jul-03 7:28 
GeneralRe: a casting problem! Pin
safee ullah21-Jul-03 22:48
safee ullah21-Jul-03 22:48 
GeneralRe: a casting problem! Pin
Jens Doose21-Jul-03 22:25
Jens Doose21-Jul-03 22:25 
Generalstd::sort() passes invalid parameter to sorting callback function Pin
s_k21-Jul-03 7:02
s_k21-Jul-03 7:02 
Hi,
I use vector of pointers to my class to store data. I insert them using push_back(). Here is my function for inserting data into vector:

[code]
UINT CVirtualLWItemManager::insertItem(LS_item* pNewItem)
{
// check if current capacity is enough
if (m_vecItems.size() > m_vecItems.capacity())
{
AfxMessageBox("m_vecItems.size() > m_vecItems.capacity()");
return 0;
}
if (m_vecItems.size() == m_vecItems.capacity())
{
// enlarge array
m_vecItems.reserve(m_vecItems.capacity() + 128);
// try again
return insertItem(pNewItem);
}
m_vecItems.push_back(pNewItem);

return 1;
}
[/code]


Here is my function that launches std::sort():

[code]
void CVirtualLWItemManager::sortItems(INT (*sort_cb)(LS_item*, LS_item*))
{
std::sort(m_vecItems.begin(), m_vecItems.end(), sort_cb);
}
[/code]


And here is my static sorting callback function:

[code]
INT CMyFileView::sortCallback(LS_item* pDataFirst, LS_item* pDataSecond)
{
ITEM_DESC* param1 = NULL;
ITEM_DESC* param2 = NULL;

param1 = (ITEM_DESC*) pDataFirst->lParam;
param2 = (ITEM_DESC*) pDataSecond->lParam;

INT iSortColumn = 0;

if (getDoc()->iViewToSort == 1)
iSortColumn = getDoc()->SortingColumnLeft;
else
iSortColumn = getDoc()->SortingColumnRight;

// Nejdrive (..), pak adresar, dale soubor
if (param1->folder > param2->folder)
return -1;
else if (param1->folder < param2->folder)
return 1;

// Trizeni podle zvoleneho sloupce
switch (iSortColumn)
{
// ASCENDING
case 0: // Podle nazvu souboru a adresaru
return param1->name.CompareNoCase((LPCTSTR) param2->name);

case 1: // Podle velikosti
if(param1->size < param2->size)
return -1;
if(param1->size > param2->size)
return 1;
break;

case 2: // Podle data
if (param1->date < param2->date)
return -1;
if (param1->date > param2->date)
return 1;
break;

// DESCENDING
case 3: // Podle nazvu souboru a adresaru
return (param1->name.CompareNoCase((LPCTSTR) param2->name)) * -1;

case 4: // Podle velikosti
if (param1->size < param2->size)
return 1;
if (param1->size > param2->size)
return -1;
break;

case 5: // Podle data
if (param1->date < param2->date)
return 1;
if (param1->date > param2->date)
return -1;
break;
}

return 0;
}
[/code]


The problem is, sometimes pDataSecond parameter passed to this function has invalid parameter, eg. 0xfdfdfdfd.

How is it possible?

Objects that are inserted to the vector are created on the heap.

Thank you a lot for any suggestion.
GeneralRe: std::sort() passes invalid parameter to sorting callback function Pin
Joaquín M López Muñoz21-Jul-03 7:18
Joaquín M López Muñoz21-Jul-03 7:18 
GeneralRe: std::sort() passes invalid parameter to sorting callback function Pin
s_k22-Jul-03 2:30
s_k22-Jul-03 2:30 
QuestionDetect USB Port Version? Pin
nng3821-Jul-03 5:57
nng3821-Jul-03 5:57 
AnswerRe: Detect USB Port Version? Pin
John M. Drescher21-Jul-03 6:14
John M. Drescher21-Jul-03 6:14 
GeneralRe: Top Window Pin
Niall Barr21-Jul-03 6:20
professionalNiall Barr21-Jul-03 6:20 
Generalwriting to the registry Pin
si_6921-Jul-03 5:28
si_6921-Jul-03 5:28 
GeneralRe: writing to the registry Pin
John M. Drescher21-Jul-03 7:11
John M. Drescher21-Jul-03 7:11 
GeneralRe: writing to the registry Pin
Dominik Reichl21-Jul-03 7:12
Dominik Reichl21-Jul-03 7:12 
GeneralRe: writing to the registry Pin
Jens Doose21-Jul-03 22:30
Jens Doose21-Jul-03 22:30 
Generalprocessing video from a TV Tuner card Pin
Cyberizen21-Jul-03 5:18
Cyberizen21-Jul-03 5:18 
GeneralRe: processing video from a TV Tuner card Pin
Ryan Binns21-Jul-03 5:26
Ryan Binns21-Jul-03 5:26 
GeneralRe: processing video from a TV Tuner card Pin
John M. Drescher21-Jul-03 17:50
John M. Drescher21-Jul-03 17:50 
GeneralAdding name to propertysheet dialog Pin
keegan21-Jul-03 5:08
keegan21-Jul-03 5:08 
GeneralRe: Adding name to propertysheet dialog Pin
G. Steudtel21-Jul-03 5:21
G. Steudtel21-Jul-03 5:21 
GeneralRe: Adding name to propertysheet dialog Pin
Ryan Binns21-Jul-03 5:25
Ryan Binns21-Jul-03 5:25 
GeneralRe: Adding name to propertysheet dialog Pin
Ryan Binns21-Jul-03 5:24
Ryan Binns21-Jul-03 5:24 
GeneralRe: Adding name to propertysheet dialog Pin
keegan21-Jul-03 6:27
keegan21-Jul-03 6:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.