WildCrustacean
WildCrustacean

Reputation: 5966

Drag and drop from Outlook attachment to VB6 application

I am experimenting with drag and drop from an outlook email attachment to a custom application. It works just fine with C#, but now I'd like to get it working in VB6. My test code looks something like this:

Private Sub grdLis_OLEDragDrop(Data As MSFlexGridLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim FileDropped As String * 256
Dim lCF_FILEGROUP As Long
Dim CF_FILEGROUP As Integer
Dim lCF_FILECONTENTS As Long
Dim CF_FILECONTENTS As Integer
Dim bData() As Byte
Dim bFileNameData(256) As Byte
Dim bData2() As Byte

  lCF_FILEGROUP = RegisterClipboardFormat("FileGroupDescriptor")
  MoveMemory CF_FILEGROUP, lCF_FILEGROUP, 2

  bData() = Data.GetData(CF_FILEGROUP)

  j = 0
  For i = 76 To 76 + 256
    bFileNameData(j) = bData(i)
    j = j + 1
  Next i
  FileDropped = Trim(StrConv(bFileNameData, vbUnicode))

  lCF_FILECONTENTS = RegisterClipboardFormat("FileContents")
  MoveMemory CF_FILECONTENTS, lCF_FILECONTENTS, 2

  bData2() = Data.GetData(CF_FILECONTENTS)

This works to get the file name, but it throws an exception on the Data.GetData(CF_FILECONTENTS) call, and the error messages says "Automation error invalid tymed".

I don't have much experience in VB6, and I have no idea what that error message means or what to do about it. Any help or insight would be appreciated.

Upvotes: 2

Views: 3485

Answers (1)

wqw
wqw

Reputation: 11991

Check out Get dropped attachments from Outlook messages for more ideas. It's using OLE heavily.

Upvotes: 2

Related Questions