Board index » cppbuilder » IDropTarget with Outlook
Mike Baker
![]() CBuilder Developer |
IDropTarget with Outlook2006-06-28 04:40:49 AM cppbuilder82 Hello all. I think this is the correct forum for this question. I am using CBuilder 6.0 and have created an IDropTarget interface to accept files from explorer into my application. This is working fine. I have also added in the code to accept attachments from Outlook which is also working fine. My problem is, I need to allow for the message itself to be dropped into my application which is not working. My class looks like below with a bunch of code left out; Most of the problem area is at the location marked THIS IS THE AREA. class ObjDropTarget : public IDropTarget { private: ..... public: ...... // IUnknown Members HRESULT __stdcall QueryInterface(REFIID iid, void **ppvObject) {....} et.c.... HRESULT __stdcall Drop(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) { ....................... unsigned short cp_format_descriptor = RegisterClipboardFormat(CFSTR_FILEDESCRIPTOR); unsigned short cp_format_contents = RegisterClipboardFormat(CFSTR_FILECONTENTS); //Set up format structure for the descriptor and contents FORMATETC descriptor_format = {cp_format_descriptor, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; FORMATETC contents_format = {cp_format_contents, NULL, DVASPECT_CONTENT, -1, TYMED_ISTREAM}; FORMATETC filename_format = {CF_TEXT, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; // Check for descriptor format type hResult = pDataObj->QueryGetData(&descriptor_format); if (hResult == S_OK) { // Check for contents format type hResult = pDataObj->QueryGetData(&contents_format); if (hResult == S_OK) { hResult = pDataObj->GetData(&descriptor_format, &stMedium); if (hResult != S_OK) { ...... } file_group_descriptor = (FILEGROUPDESCRIPTOR *) GlobalLock(stMedium.hGlobal); // For each file, get the name and copy the stream to a file for (unsigned int file_index = 0; file_index < file_group_descriptor->cItems; file_index++) { file_descriptor = file_group_descriptor->fgd[file_index]; contents_format.lindex = file_index; hResult = pDataObj->GetData(&contents_format, &stMedium); if (hResult == S_OK) // Dump stream to a file { sprintf(szFileBuff, "C:\\ACTemp\\%s", file_descriptor.cFileName); hResult = StreamToFile(stMedium.pstm, szFileBuff); strFilePath = szFileBuff; ......................... } else { THIS IS THE AREA filename_format.lindex = file_index; hResult = pDataObj->GetData(&filename_format, &stMedium); if (hResult == S_OK) { hDrop = (HANDLE)stMedium.hGlobal; WHEN THIS IS EXECUTED, THE OUTLOOK ERROR APPEARS uiCount = DragQueryFile(hDrop, -1, szFileBuff, sizeof(szFileBuff)); ................... } } } GlobalUnlock(stMedium.hGlobal); GlobalFree(stMedium.hGlobal); } } The problem is when I drop an Outlook message onto my window, I get this message from Outlook; (The operation failed due to network or other communication problems. Check your connections and try again.) I am assuming that I some how need to tell outlook wher to place the message file. So far, I have looked in all kinds of books and googled myself to death looking for hints on this one thing. If anyone know the trick, I would really appreciate it. Thanks, Mike |