OLE problem with drag and drop
-
I have implemented drag and drop on my new aplication and i have a strange error. In InitInstance method of app object i call AfxInitOle() function. Lets we call source window A and target window B. In A´s OnCreate message handler i use the following code: medium.tymed = TYMED_FILE; medium.lpszFileName = (unsigned short *)((LPCSTR)(new CString("TempDragDrop.dat"))); source->CacheData(((CLightControllerApp *)AfxGetApp())->ID_FOCUS_FORMAT,&medium); In B´s OnCreate message handler i use the following code: target.Register(this); And on OnDestroy message handler of B window I use: target.Revoke(); I have no idea of what is going wrong, so please help me. Many thanks to all you and sorry for my poor english.
-
I have implemented drag and drop on my new aplication and i have a strange error. In InitInstance method of app object i call AfxInitOle() function. Lets we call source window A and target window B. In A´s OnCreate message handler i use the following code: medium.tymed = TYMED_FILE; medium.lpszFileName = (unsigned short *)((LPCSTR)(new CString("TempDragDrop.dat"))); source->CacheData(((CLightControllerApp *)AfxGetApp())->ID_FOCUS_FORMAT,&medium); In B´s OnCreate message handler i use the following code: target.Register(this); And on OnDestroy message handler of B window I use: target.Revoke(); I have no idea of what is going wrong, so please help me. Many thanks to all you and sorry for my poor english.
i have found it, and i wish i can help anyone who finds the same problem... The cuestion is that when you call the CacheData function, you must care every value in the STGMEDIUM and FORMATETC structures. A good idea is to make something like this: ZeroMemory(pMedium, sizeof(STGMEDIUM )) and ZeroMemory(pFormatetc, sizeof(FORMATETC )) before beginning to give values to its members. You must remember too that since these two structures are passed to CacheData() they arent owned by aplication, that means for example that you can do :)something like this: pMedium = new STGMEDIUM; ...; ...->CacheData(...,pMedium, ...); ...; delete pMedium; because this will surely cause a program´s crash.:)
-
I have implemented drag and drop on my new aplication and i have a strange error. In InitInstance method of app object i call AfxInitOle() function. Lets we call source window A and target window B. In A´s OnCreate message handler i use the following code: medium.tymed = TYMED_FILE; medium.lpszFileName = (unsigned short *)((LPCSTR)(new CString("TempDragDrop.dat"))); source->CacheData(((CLightControllerApp *)AfxGetApp())->ID_FOCUS_FORMAT,&medium); In B´s OnCreate message handler i use the following code: target.Register(this); And on OnDestroy message handler of B window I use: target.Revoke(); I have no idea of what is going wrong, so please help me. Many thanks to all you and sorry for my poor english.
i have found it, and i wish i can help anyone who finds the same problem... The cuestion is that when you call the CacheData function, you must care every value in the STGMEDIUM and FORMATETC structures. A good idea is to make something like this: ZeroMemory(pMedium, sizeof(STGMEDIUM )) and ZeroMemory(pFormatetc, sizeof(FORMATETC )) before beginning to give values to its members. You must remember too that since these two structures are passed to CacheData() they arent owned by aplication, that means for example that you can do :)something like this: pMedium = new STGMEDIUM; ...; ...->CacheData(...,pMedium, ...); ...; delete pMedium; because this will surely cause a program´s crash.:)