![]() |
Wie Drag&Drop einzelner Anhänge aus Outlook?
Moin,
ich hänge schon seit Ewigkeiten an dem Thema einzelne Dateianhänge aus Outlook per Drag&Drop. Ganze Emails funktionieren. Ich habe mich gestern mit ChatGPT dran gesetzt. Mit dem Code bekomme ich auch Filedescription aber nicht den FileContent. Hat sich jemand damit schon einmal beschäftigt? Succeeded(DataObj.GetData(FormatEtc, Medium)) gibt immer false zurück
Code:
procedure Tform3.extractOutlookAttachment(DataObj: IDataObject;var FileList: TStringList);
var FormatEtc: TFormatEtc; Medium: TStgMedium; FileDescriptor: PFileGroupDescriptorW; I: Integer; Stream: IStream; FileName: string; FileHandle: THandle; FileBuffer: array of Byte; BytesRead: LongInt; const CFSTR_FILEDESCRIPTOR = 'FileGroupDescriptorW'; CFSTR_FILECONTENTS = 'FileContents'; function GetFormatEtc(Format: string): TFormatEtc; begin Result.cfFormat := RegisterClipboardFormat(PChar(Format)); Result.ptd := nil; Result.dwAspect := DVASPECT_CONTENT; Result.lindex := -1; Result.tymed := TYMED_HGLOBAL; end; begin // 1. Datei-Beschreibung abrufen FormatEtc := GetFormatEtc(CFSTR_FILEDESCRIPTOR); if Succeeded(DataObj.GetData(FormatEtc, Medium)) then try FileDescriptor := GlobalLock(Medium.hGlobal); try for I := 0 to FileDescriptor.cItems - 1 do begin FileName := GetEnvironmentVariable('TEMP') + '\'+WideCharToString(FileDescriptor.fgd[I].cFileName); FileList.add(FileName); showmessage(FileName); // 2. Datei-Inhalt abrufen FormatEtc := GetFormatEtc(CFSTR_FILECONTENTS); FormatEtc.lindex := I; // Dateiindex setzen if Succeeded(DataObj.GetData(FormatEtc, Medium)) then // Wird nie getriggert try Stream := IStream(Medium.stm); FileHandle := FileCreate(FileName); try SetLength(FileBuffer, 4096); repeat Stream.Read(@FileBuffer[0], Length(FileBuffer), @BytesRead); FileWrite(FileHandle, FileBuffer[0], BytesRead); until BytesRead = 0; finally FileClose(FileHandle); end; finally ReleaseStgMedium(Medium); end; end; finally GlobalUnlock(Medium.hGlobal); end; finally ReleaseStgMedium(Medium); end; end; |
AW: Wie Drag&Drop einzelner Anhänge aus Outlook?
Ich glaube, dass du in FormatEtc zu wenige Werte setzt. Ich glaube nach Lektüre der API du müsstest setzen:
cfFormat = CF_HDROP dwAspect = DVASPECT_CONTENT tymed = TYMED_HGLOBAL (oder da du einen Stream nutzt wohl TYMED_ISTREAM) |
AW: Wie Drag&Drop einzelner Anhänge aus Outlook?
Mein Held :-)
tymed = TYMED_ISTREAM war die Lösung. Vielen Dank. |
AW: Wie Drag&Drop einzelner Anhänge aus Outlook?
Moin,
ich hätte noch ein paar Anregungen: Die Schleife für
Delphi-Quellcode:
ist meiner Ansicht nicht nötig, da man aus Outlook nur eine Datei per Drag ziehen kann. Außerdem steht
FileDescriptor.cItem
Delphi-Quellcode:
nicht für den Dateiindex. Das erneute Setzen nach dem Aufruf von
FormatEtc.lindex
Delphi-Quellcode:
wird deshalb nicht benötigt.
GetFormatEtc
|
AW: Wie Drag&Drop einzelner Anhänge aus Outlook?
Ich hab mich das auch gefragt, aber ich benutze die Suite von Anders Melander und Sven Harazim, aber das Ding ist so riesig, dass ich nicht weiß, wo man da was einfügen könnte.
Zitat:
|
AW: Wie Drag&Drop einzelner Anhänge aus Outlook?
kommt der Code denn mit Win64 Outlook und Win32 Anwendung klar? Da gibts immer mal wieder Probleme in der Drag&Drop Bibliothek.
|
AW: Wie Drag&Drop einzelner Anhänge aus Outlook?
Zitat:
|
AW: Wie Drag&Drop einzelner Anhänge aus Outlook?
Zitat:
|
AW: Wie Drag&Drop einzelner Anhänge aus Outlook?
Zitat:
Zitat:
Die bauen da aber auch gefühlt alle 1-2 Jahre alles komplett um, damit uns nicht langweilig wird. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:54 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz