purce

purce

  • NA
  • 3
  • 0

Drag and Drop between c++ OLE and C#

Jul 16 2004 2:05 AM
Im working on a project where part of the project is in C++ and the other part is in C#. I want to enable draging and droping text between the 2 parts. So in my C++ I have a drag function from a tree void CDragsourceDlg::OnBegindragTree1(NMHDR* pNMHDR, LRESULT* pResult) { HGLOBAL hGlobal = GlobalAlloc( GMEM_MOVEABLE, 5); LPSTR pChar = (LPSTR) GlobalLock( hGlobal ); strcpy(pChar, "test"); GlobalUnlock (hGlobal); COleDataSource data; data.CacheGlobalData (CF_TEXT, hGlobal); data.DoDragDrop(DROPEFFECT_COPY, NULL, NULL); *pResult = 0; } and in C# i have a text box recieving the text private void textBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.Text)) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; } private void textBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { textBox1.Text = e.Data.GetData(DataFormats.Text).ToString(); } Now the text gets across into my C# text box .. but the C++ program asserts and crashes on exit. Its easy enough to test with 2 simple programs .. and I have no idea what is causing the problem. Is there another way I should be implementing my source or destination?

Answers (1)