Advertisement

07.20.2008 at 07:08PM PDT, ID: 23580768
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

AccessViolation calling COleDataSource::DoDragDrop from C++/CLI

Asked by AngryLoop in Microsoft Visual C++, C# Programming Language, Microsoft Visual C++.Net

Tags:

Here's a quick background on what I'm trying to acomplish:

I'm trying to drag drop virtual files by deriving System::Windows::Forms::ListView in my own class and using unmanaged code to delay render.

Here's my OnItemDrag override:
1 virtual void OnItemDrag(ItemDragEventArgs ^e) override  
2 {  
3     UINT uFileCount = this->SelectedItems->Count;  
4     UINT uBuffSize = sizeof(FILEGROUPDESCRIPTOR) +    
5         (uFileCount-1) * sizeof(FILEDESCRIPTOR);  
6     HGLOBAL hFileDescriptor = GlobalAlloc (    
7         GHND | GMEM_SHARE, uBuffSize );  
8     if(hFileDescriptor)  
9     {  
10         FILEGROUPDESCRIPTOR* pGroupDescriptor =    
11             (FILEGROUPDESCRIPTOR*) GlobalLock ( hFileDescriptor );  
12         if(pGroupDescriptor)  
13         {  
14             FILEDESCRIPTOR* pFileDescriptorArray =    
15                 (FILEDESCRIPTOR*)((LPBYTE)pGroupDescriptor + sizeof(UINT));  
16             pGroupDescriptor->cItems = uFileCount;  
17             int index = 0;  
18             m_pDataSrc->m_Files->RemoveAll();  
19             for (int i = 0; i < uFileCount; ++i)  
20             {  
21                 ZeroMemory(&pFileDescriptorArray[index],    
22                     sizeof(FILEDESCRIPTOR));                      
23  
24                 pin_ptr<const wchar_t> wch = PtrToStringChars(this->SelectedItems[i]->Text);  
25  
26                 CString fileName(wch);  
27  
28                 lstrcpy ( pFileDescriptorArray[index].cFileName, fileName );  
29  
30                 m_pDataSrc->m_Files->Add(pFileDescriptorArray[index].cFileName);  
31                 pFileDescriptorArray[index].dwFlags = FD_FILESIZE|FD_ATTRIBUTES;  
32                 pFileDescriptorArray[index].nFileSizeLow = 512;  
33                 pFileDescriptorArray[index].nFileSizeHigh = 0;  
34                 pFileDescriptorArray[index].dwFileAttributes = FILE_ATTRIBUTE_NORMAL;  
35                 index++;  
36             }  
37         }  
38         else  
39         {  
40             GlobalFree ( hFileDescriptor );  
41         }  
42     }  
43     GlobalUnlock ( hFileDescriptor );      
44  
45     FORMATETC etcDescriptor = {    
46         RegisterClipboardFormat(CFSTR_FILEDESCRIPTOR),    
47         NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };  
48         m_pDataSrc->CacheGlobalData ( RegisterClipboardFormat(  
49             CFSTR_FILEDESCRIPTOR), hFileDescriptor, &etcDescriptor );  
50  
51     FORMATETC etcContents = {    
52         RegisterClipboardFormat(CFSTR_FILECONTENTS),    
53         NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };  
54  
55     m_pDataSrc->DelayRenderFileData(  
56         RegisterClipboardFormat(CFSTR_FILECONTENTS),    
57         &etcContents);  
58  
59     DROPEFFECT dwEffect = m_pDataSrc->DoDragDrop (    
60         DROPEFFECT_COPY | DROPEFFECT_MOVE );              
61  
62     if(dwEffect == DROPEFFECT_NONE )  
63     {  
64         GlobalFree( hFileDescriptor );  
65     }    
66 }  

I'm getting an AccessViolationException on line 59 - the call to DoDragDrop.

Here's the definition of m_pDataSrc:
protected:  
    CMyOleDataSource * m_pDataSrc;  

It gets instanciated using new in the class constructor.

Here is the implementation of CMyOleDataSource:

[.h file]
1  
2 #pragma once  
3  
4 #include <afxwin.h>         // MFC core and standard components  
5 #include <afxext.h>         // MFC extensions  
6  
7 #include <afxdisp.h>        // MFC Automation classes  
8  
9 #ifndef _AFX_NO_OLE_SUPPORT  
10 #include <afxdtctl.h>       // MFC support for Internet Explorer 4 Common Controls  
11 #endif  
12 #ifndef _AFX_NO_AFXCMN_SUPPORT  
13 #include <afxcmn.h>         // MFC support for Windows Common Controls  
14 #endif // _AFX_NO_AFXCMN_SUPPORT  
15 #include <afxole.h>  
16  
17 // CMyOleDataSource command target  
18  
19 class CMyOleDataSource : public COleDataSource  
20 {  
21     DECLARE_DYNAMIC(CMyOleDataSource)  
22  
23 public:  
24     CMyOleDataSource();  
25     virtual ~CMyOleDataSource() { delete m_Files; }  
26     virtual BOOL OnRenderFileData(LPFORMATETC lpFormatEtc,CFile* pFile);  
27     CStringArray *m_Files;  
28  
29 protected:  
30     DECLARE_MESSAGE_MAP()  
31 };  

[.cpp file]
1 // MyOleDataSource.cpp : implementation file  
2 //  
3  
4 #include "stdafx.h"
5 #include "MyOleDataSource.h"  
6  
7  
8 // CMyOleDataSource  
9  
10 IMPLEMENT_DYNAMIC(CMyOleDataSource, COleDataSource)  
11  
12  
13 CMyOleDataSource::CMyOleDataSource()  
14 {  
15     m_Files = new CStringArray();  
16 }  
17  
18 BEGIN_MESSAGE_MAP(CMyOleDataSource, COleDataSource)  
19 END_MESSAGE_MAP()  
20  
21  
22  
23 // CMyOleDataSource message handlers  
24  
25 BOOL CMyOleDataSource::OnRenderFileData(  
26     LPFORMATETC lpFormatEtc,CFile* pFile)  
27 {  
28     if(lpFormatEtc->cfFormat ==    
29         RegisterClipboardFormat(CFSTR_FILECONTENTS))  
30     {      
31         HGLOBAL hGlob = NULL;  
32         const int buffSize = 512;  
33         hGlob = GlobalAlloc(GMEM_FIXED, buffSize);  
34         if(hGlob)  
35         {  
36             LPBYTE pBytes = (LPBYTE)GlobalLock(hGlob);            
37             if(pBytes)  
38             {  
39                 memset(pBytes, (int) m_Files->GetAt(  
40                     lpFormatEtc->lindex)[0], buffSize);  
41                 pFile->Write(pBytes,buffSize);                
42             }  
43             GlobalUnlock(hGlob);  
44         }  
45         GlobalFree(hGlob);  
46         return TRUE;  
47     }  
48     return COleDataSource::OnRenderFileData(  
49         lpFormatEtc, pFile);  
50 }  

Any ideas why I would be getting an AccessViolation?

Thanks,
AngryLoopStart Free Trial
 
 
[+][-]07.22.2008 at 05:32AM PDT, ID: 22058591

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 04:41AM PDT, ID: 22077947

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 09:06PM PDT, ID: 22085913

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.25.2008 at 02:04PM PDT, ID: 22092302

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.25.2008 at 02:19PM PDT, ID: 22092413

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.25.2008 at 02:32PM PDT, ID: 22092476

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.25.2008 at 03:07PM PDT, ID: 22092653

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.26.2008 at 03:37PM PDT, ID: 22096511

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.28.2008 at 10:52AM PDT, ID: 22105268

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.28.2008 at 03:38PM PDT, ID: 22107345

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.29.2008 at 08:09AM PDT, ID: 22112237

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.29.2008 at 01:13PM PDT, ID: 22115158

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.29.2008 at 02:17PM PDT, ID: 22115772

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.29.2008 at 03:19PM PDT, ID: 22116197

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C++, C# Programming Language, Microsoft Visual C++.Net
Tags: C++/CLI
Sign Up Now!
Solution Provided By: DanRollins
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.18.2008 at 02:32PM PDT, ID: 22255663

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080924-EE-VQP-39 / EE_QW_2_20070628