Click here to Skip to main content
15,906,626 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: percentile in C Pin
Anonymous4-Jul-04 14:20
Anonymous4-Jul-04 14:20 
GeneralRe: percentile in C Pin
Sumit Kapoor4-Jul-04 14:32
Sumit Kapoor4-Jul-04 14:32 
GeneralRe: percentile in C Pin
Antti Keskinen4-Jul-04 22:02
Antti Keskinen4-Jul-04 22:02 
GeneralIXMLDOMxxx functions Pin
CaesarCZ4-Jul-04 13:16
CaesarCZ4-Jul-04 13:16 
GeneralRe: IXMLDOMxxx functions Pin
Sumit Kapoor4-Jul-04 13:57
Sumit Kapoor4-Jul-04 13:57 
GeneralDesparate: OLE Drag&Drop ClistCtrls Bombs Pin
otrcomm4-Jul-04 12:30
otrcomm4-Jul-04 12:30 
GeneralRe: Desparate: OLE Drag&Drop ClistCtrls Bombs Pin
Anonymous7-Jul-04 14:17
Anonymous7-Jul-04 14:17 
GeneralRe: Desparate: OLE Drag&Drop ClistCtrls Bombs Pin
otrcomm7-Jul-04 20:17
otrcomm7-Jul-04 20:17 
Hello,

The error message is always the same:

Instruction at "0x77fcc452" referenced memory at "0x676e6973". The memory could not be "written".

And then when I go into debug, I get:

Unhandled exception ... (NTDLL.DLL): 0xC0000005: Access Violation.

I have a structure defined:

typedef struct {
LVITEM* plvi;
CString sSubject;
CString sFrom;
CString smsg_num;
} ListInfo, *plvItem;

and

ListInfo* rowdata[MAXMESSAGES * sizeof(ListInfo*)];

Where MAXMESSAGES is defined to be 2000.

The code I use for OnBeginDrag:

void CPopListCtrl::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;

FILE* m_fpTmp;
CString sMsgCount;

StartInRammedEarth = False;
StartInCob = False;
StartInAdobe = False;

// Get the CWnd handle of the current control where we start dragging!!
CPoint pt;
GetCursorPos(&pt);
CWnd* pWnd = WindowFromPoint(pt);

int iItem = ((NM_LISTVIEW*) pNMHDR)->iItem;

if (pWnd->GetDlgCtrlID() == IDC_LIST_RAMMEDEARTH)
StartInRammedEarth = True;
else if (pWnd->GetDlgCtrlID() == IDC_LIST_COB)
StartInCob = True;
else if (pWnd->GetDlgCtrlID() == IDC_LIST_ADOBE)
StartInAdobe = True;

m_iDragItem = iItem; // Item on which D&D is started
m_iDropItem = -1; // Not yet known
m_bDragging = TRUE; // D&D started

m_bSource = TRUE; // We start D&D on the source
m_bTarget = FALSE; // Not yet known

m_nItem = GetSelectedCount(); // Used for counting number of selected items

// Allocate an array for saving item indexes
m_pSaveIndItem = new int[m_nItem];

// This doesn't work!
// HGLOBAL hgData = GlobalAlloc(GPTR,m_nItem*sizeof(ListInfo)+2*sizeof(int));
// ASSERT(hgData!=NULL);
// char* p = (char*) GlobalLock(hgData);
// ASSERT(p!=NULL);

m_fpTmp = fopen("incomingmail\\msgcount" , "wb");
sMsgCount.Format(_T("%d"),m_nItem);
fprintf(m_fpTmp,sMsgCount);
fclose(m_fpTmp);

LVITEM* plvitem;
ListInfo* pItem;

int jItem = -1, i=0;
while ((jItem = GetNextItem(jItem,LVNI_ALL | LVNI_SELECTED)) > -1)
{
ASSERT(i>=0 && i <m_nItem);

plvitem = new LVITEM;
ZeroMemory(plvitem, sizeof(LVITEM));
pItem = new ListInfo;
//If you use ZeroMemory on the lvItem struct, it creates an error when you try to set sFrom
//ZeroMemory(pItem, sizeof(ListInfo));
pItem->plvi = plvitem;
pItem->plvi->iItem = jItem;
pItem->plvi->mask = LVIF_TEXT;
//since this is a pointer to the string, we need a new pointer to a new string on the heap
pItem->plvi->pszText = new char;
pItem->plvi->cchTextMax = 255;

GetItem(pItem->plvi);
pItem->sSubject = GetItemText(jItem, 0);
pItem->sFrom = GetItemText(jItem, 1);
pItem->smsg_num = GetItemText(jItem, 2);
rowdata[i] = pItem;
m_pSaveIndItem[i] = jItem;
i++;
}

HGLOBAL hgData = GlobalAlloc(GPTR,(m_nItem+1)*sizeof(rowdata));
ASSERT(hgData!=NULL);

// ListInfo* lpData[m_nItem * sizeof(ListInfo*)]=(ListInfo*)GlobalLock(hgData);
ListInfo* lpData=(ListInfo*)GlobalLock(hgData);

lpData = *rowdata;

// Cache the data, and initiate DragDrop
m_COleDataSource.CacheGlobalData(CF_TEXT, hgData);

// Set drag/drop source rectangle (screen coord)
SetDragSourceRect();

DROPEFFECT dropEffect = m_COleDataSource.DoDragDrop(DROPEFFECT_COPY|DROPEFFECT_MOVE,NULL);

if (m_bRemove && (dropEffect&DROPEFFECT_MOVE)==DROPEFFECT_MOVE)
{
// Delete items in reverse order so that indexes are preserved
for (i=m_nItem-1; i>=0; i--)
{
jItem = m_pSaveIndItem[i];

if (m_bSource && m_bTarget)
{
ASSERT(m_iDropItem>=0);
if (jItem > m_iDropItem) jItem += m_nItem;
}
BOOL bSuccess = DeleteItem(jItem);
ASSERT(bSuccess);
}

}
m_bSource = FALSE;
m_bTarget = FALSE;
m_iDropItem = -1;
delete[] m_pSaveIndItem;
m_pSaveIndItem = NULL;
m_nItem = 0;
*pResult = 0;
}

and the code I use for OnDrop


BOOL COleListCtrlDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
DROPEFFECT dropEffect, CPoint point )
{

FILE* m_fpTmp;
CString sMsgCount;
char c;
int nItem;
int iNewItem;

HGLOBAL hGlobal;
ListInfo* pData;

// TRACE("\nOnDrop");

CPopListCtrl* pDDList = (CPopListCtrl*) pWnd;

// Stop the scroll timer if it's running.
pDDList->KillTimer (1);

// Flag the list as target
pDDList->m_bTarget = TRUE;

if (pWnd->GetDlgCtrlID() == IDC_LIST_RAMMEDEARTH) {
RAMMEDEARTH = True;
COB = False;
} else if (pWnd->GetDlgCtrlID() == IDC_LIST_COB) {
COB = True;
RAMMEDEARTH = False;
}

// Find out the drop item
int iItem;
int iItemCountRammedEarth = m_listRammedEarth.GetItemCount();
int iItemCountCob = m_listCob.GetItemCount();
if (pDDList->GetItemCount() == 0)
iItem = 0; // List is empty
else
{
// Find drop element in list
UINT nFlags;
point.y += 5;
iItem = pDDList->HitTest (point, &nFlags);
if (iItem == -1)
{
// Get coordinates of top and bottom visible points
int iTopItem = pDDList->GetTopIndex();
int iBotItem = iTopItem + pDDList->GetCountPerPage() -1;
if (iBotItem > pDDList->GetItemCount()-1)
iBotItem = pDDList->GetItemCount() - 1;
CPoint topPoint, botPoint;
BOOL bSuccess = pDDList->GetItemPosition(iTopItem, &topPoint);
ASSERT(bSuccess);
bSuccess = pDDList->GetItemPosition(iBotItem, &botPoint);
ASSERT(bSuccess);

if (point.y <= topPoint.y+5)
iItem = 0;
else if (point.y >botPoint.y)
iItem = pDDList->GetItemCount(); // Add at the end
else
{
// If there was an error adding the text to the control
// return FALSE so that the text is not removed from
// the drop source
return FALSE;
}
}
}

// iItem in the next available index number in dropbox.
pDDList->m_iDropItem = iItem;
ASSERT(pDDList->m_iDropItem>=0);

if (pDDList->m_bSource && pDDList->m_bTarget)
{
// Check that we don't drop on dragged items
TRACE("\niItem=%d pSaveInItem[0]=%d pSaveInItem[0]=%d",iItem,pDDList->m_pSaveIndItem[0],pDDList->m_pSaveIndItem[pDDList->m_nItem-1]);
if (iItem >= pDDList->m_pSaveIndItem[0] &&
iItem <= pDDList->m_pSaveIndItem[pDDList->m_nItem-1])
{
// Display an error message if the move is illegal.
AfxMessageBox (_T ("An item can't be dropped onto itself"));
pDDList->SelectDropTarget(-1);
// If there was an error adding the text to the control
// return FALSE so that the text is not removed from
// the drop source
return FALSE;
}
}

// Get List data from COleDataObject
hGlobal = pDataObject->GetGlobalData(CF_TEXT);
pData=(ListInfo*)GlobalLock(hGlobal);
ASSERT(pData!=NULL);

// Add the item(s) to the list
m_fpTmp = fopen("incomingmail\\msgcount" , "rb");

do {
c = fgetc (m_fpTmp);
sMsgCount += c;
} while (c != EOF);

fclose(m_fpTmp);

nItem = atoi((LPCSTR)sMsgCount);

for (int i=0; i<nItem; i++)
{

if (RAMMEDEARTH) {

iNewItem = m_listRammedEarth.InsertItem(i+iItemCountRammedEarth,rowdata[i]->sSubject);
m_listRammedEarth.SetItemText(i+iItemCountRammedEarth,1,rowdata[i]->sFrom);
m_listRammedEarth.SetItemText(i+iItemCountRammedEarth,2,rowdata[i]->smsg_num);

// iNewItem = m_listRammedEarth.InsertItem(i+iItemCountRammedEarth,pData[i]->sSubject);
// m_listRammedEarth.SetItemText(i+iItemCountRammedEarth,1,pData[i]->sFrom);
// m_listRammedEarth.SetItemText(i+iItemCountRammedEarth,2,pData[i]->smsg_num);

} else if (COB) {

iNewItem = m_listCob.InsertItem(i+iItemCountCob,rowdata[i]->sSubject);
m_listCob.SetItemText(i+iItemCountCob,1,rowdata[i]->sFrom);
m_listCob.SetItemText(i+iItemCountCob,2,rowdata[i]->smsg_num);

// iNewItem = m_listCob.InsertItem(i+iItemCountCob,pData[i]->sSubject);
// m_listCob.SetItemText(i+iItemCountCob,1,pData[i].sFrom);
// m_listCob.SetItemText(i+iItemCountCob,2,pData[i]->smsg_num);
}

} // End for (int i=0; i<nItem; i++)

// Unlight all list items
pDDList->SelectDropTarget(-1);

// Select the newly added item.
BOOL bSuccess = pDDList->SetItemState(iNewItem, LVIS_SELECTED, LVIS_SELECTED);

// Unlock memory
GlobalUnlock(hGlobal);

return TRUE;

} // End OnDrop

If you can see what I am doing wrong, I really would appreciate it!

Thanks,
Murrah Boswell
GeneralRe: Desparate: OLE Drag&amp;Drop ClistCtrls Bombs Pin
SRV8-Jul-04 3:49
SRV8-Jul-04 3:49 
GeneralRe: Desparate: OLE Drag&amp;Drop ClistCtrls Bombs Pin
otrcomm8-Jul-04 10:18
otrcomm8-Jul-04 10:18 
Generalunsigned convert Pin
Scozturk4-Jul-04 8:33
professionalScozturk4-Jul-04 8:33 
GeneralRe: unsigned convert Pin
Michael Dunn4-Jul-04 8:51
sitebuilderMichael Dunn4-Jul-04 8:51 
Questionhow to get dial-up connection status Pin
J.Z4-Jul-04 7:15
J.Z4-Jul-04 7:15 
AnswerRe: how to get dial-up connection status Pin
Scozturk4-Jul-04 8:32
professionalScozturk4-Jul-04 8:32 
GeneralIncludes Pin
Dennis Gourjii4-Jul-04 7:12
Dennis Gourjii4-Jul-04 7:12 
GeneralRe: Includes Pin
J.B.4-Jul-04 7:29
J.B.4-Jul-04 7:29 
GeneralRe: Includes Pin
Dennis Gourjii4-Jul-04 8:44
Dennis Gourjii4-Jul-04 8:44 
GeneralRe: Includes Pin
Ravi Bhavnani4-Jul-04 8:53
professionalRavi Bhavnani4-Jul-04 8:53 
GeneralRe: Includes Pin
Dennis Gourjii5-Jul-04 5:16
Dennis Gourjii5-Jul-04 5:16 
GeneralBOOL to bool conversion Pin
J.B.4-Jul-04 6:39
J.B.4-Jul-04 6:39 
GeneralRe: BOOL to bool conversion Pin
User 66584-Jul-04 7:07
User 66584-Jul-04 7:07 
GeneralRe: BOOL to bool conversion Pin
Tim Smith4-Jul-04 7:12
Tim Smith4-Jul-04 7:12 
GeneralRe: BOOL to bool conversion Pin
J.B.4-Jul-04 7:19
J.B.4-Jul-04 7:19 
GeneralRe: BOOL to bool conversion Pin
User 66584-Jul-04 7:34
User 66584-Jul-04 7:34 
GeneralRe: BOOL to bool conversion Pin
A T I F4-Jul-04 22:14
A T I F4-Jul-04 22:14 

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.