JohnBPrice
asked on
Now 500 points! Drag and Drop Outlook mail messages into VB 6.0 app
I need to support dragging mail messages from outlook 2002 into my VB 6 app (whereupon I will tie them to a customer record & store them in the database. I can get the OLEDragDrop event with a DataObject fine, but I don't know how to use the DataObject to get to the outlook.mailitem. The DataObject i get supports formats 1, 13, -16370, and -16193. Format 1 is text, and the text contains this
From Subject Received Size
John Doe Great News for Friends of Animals Tue 5/18/2004 2:51 PM 8 KB
which is clearly the columns I have shown in my outlook inbox. Format 13 looks the same. Formats -16370 and -16193 contain some binary info and look promising, but I haven't been able to find anything about them.
Does anyone know how to decode these formats and get to the outlook.mailitem from the OLE dropped DataObject?
I'll post the extra pts in a separate question...
From Subject Received Size
John Doe Great News for Friends of Animals Tue 5/18/2004 2:51 PM 8 KB
which is clearly the columns I have shown in my outlook inbox. Format 13 looks the same. Formats -16370 and -16193 contain some binary info and look promising, but I haven't been able to find anything about them.
Does anyone know how to decode these formats and get to the outlook.mailitem from the OLE dropped DataObject?
I'll post the extra pts in a separate question...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
If anyone cares, it turned out to be a lot simpler than suggested in the link above, the C++ code is:
STDMETHODIMP CDObject::SaveToFile(long pDataObjectAddress, BSTR FileName)
{
AFX_MANAGE_STATE(AfxGetSta ticModuleS tate())
//Copies the passed DataObject to a file
HRESULT hr = S_OK;
IDataObject *pDataObject;
pDataObject = (IDataObject*) pDataObjectAddress; //cast the passed pointer into a *IDataObject
//Get the clipboard
// Important: these strings need to be non-Unicode (don't compile UNICODE)
unsigned short cp_format_descriptor = RegisterClipboardFormat(CF STR_FILEDE SCRIPTOR);
unsigned short cp_format_contents = RegisterClipboardFormat(CF STR_FILECO NTENTS);
//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};
// Check for contents format type
hr = pDataObject->QueryGetData( &contents_ format);
if (hr != S_OK) return hr;
// Get the descriptor information
STGMEDIUM storage= {0,0,0};
STGMEDIUM ContentStorage = {0,0,0};
contents_format.lindex = 0;
contents_format.tymed = TYMED_ISTORAGE;
hr = pDataObject->GetData(&cont ents_forma t, &ContentStorage);
if (hr != S_OK) return hr;
//Save the passed storage to the filename passed
IStorage *FileStg;
//hr = StgCreateDocfile(L"C:\\mte st\\MyMsg. msg",STGM_ READWRITE + STGM_CREATE +STGM_SHARE_EXCLUSIVE ,0,&FileStg);
hr = StgCreateStorageEx(FileNam e,STGM_REA DWRITE + STGM_CREATE +STGM_SHARE_EXCLUSIVE ,STGFMT_STORAGE ,0,0,0,IID_IStorage ,(void**)&FileStg);
if (hr != S_OK) return hr;
hr = ContentStorage.pstg->CopyT o(0,0,0,Fi leStg);
FileStg->Commit(STGC_DEFAU LT );
FileStg->Release();
return hr;
}
And the VB code is
Private Sub imgEMail_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
Dim DObjectHelper As New DATAOBJECTHELPERLib.DObjec t
Dim DObjectAddr As Long
Dim MsgData() As Byte
If (Data.GetFormat(-16370) = True) Then 'e-mail attachment
MoveMemory DObjectAddr, ByVal ObjPtr(Data) + 16, 4 'the real IDataObject pointer is 16 bytes into the VB data object
Call DObjectHelper.SaveToFile(D ObjectAddr , "C:\TempMsg.msg")
End If
End Sub
STDMETHODIMP CDObject::SaveToFile(long pDataObjectAddress, BSTR FileName)
{
AFX_MANAGE_STATE(AfxGetSta
//Copies the passed DataObject to a file
HRESULT hr = S_OK;
IDataObject *pDataObject;
pDataObject = (IDataObject*) pDataObjectAddress; //cast the passed pointer into a *IDataObject
//Get the clipboard
// Important: these strings need to be non-Unicode (don't compile UNICODE)
unsigned short cp_format_descriptor = RegisterClipboardFormat(CF
unsigned short cp_format_contents = RegisterClipboardFormat(CF
//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};
// Check for contents format type
hr = pDataObject->QueryGetData(
if (hr != S_OK) return hr;
// Get the descriptor information
STGMEDIUM storage= {0,0,0};
STGMEDIUM ContentStorage = {0,0,0};
contents_format.lindex = 0;
contents_format.tymed = TYMED_ISTORAGE;
hr = pDataObject->GetData(&cont
if (hr != S_OK) return hr;
//Save the passed storage to the filename passed
IStorage *FileStg;
//hr = StgCreateDocfile(L"C:\\mte
hr = StgCreateStorageEx(FileNam
if (hr != S_OK) return hr;
hr = ContentStorage.pstg->CopyT
FileStg->Commit(STGC_DEFAU
FileStg->Release();
return hr;
}
And the VB code is
Private Sub imgEMail_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
Dim DObjectHelper As New DATAOBJECTHELPERLib.DObjec
Dim DObjectAddr As Long
Dim MsgData() As Byte
If (Data.GetFormat(-16370) = True) Then 'e-mail attachment
MoveMemory DObjectAddr, ByVal ObjPtr(Data) + 16, 4 'the real IDataObject pointer is 16 bytes into the VB data object
Call DObjectHelper.SaveToFile(D
End If
End Sub
ASKER
Alas, as you can see above and in my other question, I've been instructed that I am not allowed to give 1000 pts. by posting two questions, you get an A though!