Outlook 2003 - extract multiple image attachments from clipboard

J

Jake

We have been working on a project to extract multiple image files from the
Outlook clipboard when attachments are copied to it. The project works fine
in
all flavors of Outlook but fails in Outlook 2003 .

I understand this may be due to changes made in Outlook 2003.


The following works with previous Outlook versions but not in 2003:

In The ProcessFileContents procedure, even though the FormatETC structure
has been filled correctly, it still returns an error ... with a HResult <>
0.


What changes are necessary to make it work in Outlook 2003?

Thanks


sample code below......

-----------------------------
....................
var
Form1: TForm1;
CF_FILEGROUPDESCRIPTORA: UINT = 0;
CF_FILEGROUPDESCRIPTORW: UINT = 0;
CF_FILECONTENTS: UINT = 0;

implementation

{$R *.dfm}

procedure TForm1.HandleFiles(dataObj: IDataObject; fetc: TFormatEtc; stgm:
TSTGMedium; DstFile: string);
begin
//get file from a created file stream
end;

procedure TForm1.ProcessFileContents(Obj: IDataObject; Index: UINT;
FileName: string);
var
Fetc: FORMATETC;
Medium: STGMEDIUM;
HR: HRESULT;
FormatName: array[0..128] of Char;
begin
Fetc.cfFormat := CF_FILECONTENTS;
Fetc.ptd := nil;
Fetc.dwAspect := DVASPECT_CONTENT;
Fetc.lindex := Index;
Fetc.tymed := TYMED_HGLOBAL or TYMED_ISTREAM or TYMED_ISTORAGE;

GetClipboardFormatName(FEtc.cfFormat, FormatName, SizeOf(FormatName));

Memo1.Lines.Add('---------------Retrieving file:--------------------');
Memo1.Lines.Add('Format: [' + IntToStr(Fetc.cfFormat)+'], '+
string(FormatName));
Memo1.Lines.Add('PTD: ' + IntToStr(Longint(Fetc.ptd)));
Memo1.Lines.Add('Aspect: ' + IntToStr(Fetc.dwAspect));
Memo1.Lines.Add('Lindex: ' + IntToStr(Fetc.lindex));
Memo1.Lines.Add('Tymed: ' + IntToStr(Fetc.tymed));
Memo1.Lines.Add('---------------------------------------------------');

HR := Obj.GetData(Fetc, Medium);
Memo1.Lines.Add('HR = [' + IntToStr(HR)+'], '+DSUtil.GetErrorString(HR));
if SUCCEEDED(HR) then
begin
case Medium.tymed of
TYMED_HGLOBAL: // use Medium.hGlobal as needed ...
Memo1.Lines.Add('TYMED_HGLOBAL');
TYMED_ISTREAM:
begin
Memo1.Lines.Add('TYMED_ISTREAM');
HandleFiles(Obj, FEtc, Medium, Edit1.Text + FileName);
end;
TYMED_ISTORAGE :
begin
Memo1.Lines.Add('TYMED_ISTORAGE');
end;
end;
ReleaseStgMedium(Medium);
end else
Memo1.Lines.Add('Failed');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
DataObj : IDataObject;
Fetc: FORMATETC;
Medium: STGMEDIUM;
Enum: IEnumFORMATETC;
Group: Pointer;
S: string;
FormatName: array[0..128] of char;
I: UINT;
FileNameA: AnsiString;
FileNameW: WideString;
HR: HResult;
begin
memo1.Clear;
if (OleGetClipboard(DataObj) <> S_OK) then Exit;
if DataObj = nil then exit;
if FAILED(DataObj.EnumFormatEtc(DATADIR_GET, Enum)) then Exit;

while Enum.Next(1, Fetc, nil) = S_OK do
begin
S := StringFromClipboardFormat(fetc.cfFormat);
GetClipboardFormatName(FEtc.cfFormat, FormatName, SizeOf(FormatName));

Memo1.Lines.Add('[Clipboard Format: ' + S + ' ]');
Memo1.Lines.Add('[Format: ' + FormatName + ', ' +
IntToStr(Fetc.cfFormat) + ' ]');
Memo1.Lines.Add('[Aspect: ' + IntToStr(Fetc.dwAspect) + ' ]');
Memo1.Lines.Add('[Lindex: ' + IntToStr(Fetc.lindex) + ' ]');
Memo1.Lines.Add('[Tymed: ' + IntToStr(Fetc.tymed) + ' ]');


if (S = 'FileGroupDescriptor') or
(Fetc.cfFormat in [CF_FILEGROUPDESCRIPTORA, CF_FILEGROUPDESCRIPTORW])
then
begin
Showmessage('workin');
HR := DataObj.GetData(Fetc, Medium);
Memo1.Lines.Add('[ HResult =
'+inttostr(HR)+DSUtil.GetErrorString(HR)+'] ');
if Failed(HR) then Exit;
case Medium.tymed of
TYMED_HGLOBAL :
begin
Memo1.Lines.Add('[ Using Tymed_HGLOBAL ]');
Group := GlobalLock(Medium.hGlobal);
try
if FEtc.cfFormat = CF_FILEGROUPDESCRIPTORW then
begin
for I := 0 to PFileGroupDescriptorW(Group)^.cItems-1 do
begin
FileNameW := PFileGroupDescriptorW(Group)^.fgd.cFileName;
Memo1.Lines.Add('filenameW : ' + Filenamew);
ProcessFileContents(DataObj, I, FilenameW);
end;
end else
begin
for I := 0 to PFileGroupDescriptorA(Group)^.cItems-1 do
begin
FileNameA := PFileGroupDescriptorA(Group)^.fgd.cFileName;
memo1.Lines.Add('filenameA : ' + FileNameA);
ProcessFileContents(DataObj, I, FileNameA);
end;
end;
finally
GlobalUnlock(Medium.hGlobal);
end;
end; //tymed_hglobal
TYMED_ISTREAM :
Memo1.Lines.Add('[ Using Tymed_ISTREAM ]');
TYMED_ISTORAGE :
Memo1.Lines.Add('[ Using Tymed_ISTORAGE ]')
end;
ReleaseStgMedium(Medium);
end;
end;
end;

initialization
CF_FILEGROUPDESCRIPTORA := RegisterClipboardFormat(CFSTR_FILEDESCRIPTORA);
CF_FILEGROUPDESCRIPTORW := RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW);
CF_FILECONTENTS := RegisterClipboardFormat(CFSTR_FILECONTENTS);

end.

-------------------------------------------------------------
RESULT
-------------------------------------------------------------
[Clipboard Format: DataObject ]
[Format: DataObject, 49161 ]
[Aspect: 1 ]
[Lindex: -1 ]
[Tymed: 5 ]
[Clipboard Format: FileGroupDescriptor ]
[Format: FileGroupDescriptor, 49331 ]
[Aspect: 1 ]
[Lindex: -1 ]
[Tymed: 5 ]

[ HResult = 0The operation completed successfully. ]
[ Using Tymed_HGLOBAL ]
filenameA : IMGP2151.jpg

---------------Retrieving file:--------------------

Format: [49330], FileContents
PTD: 0
Aspect: 1
Lindex: 0
Tymed: 13
---------------------------------------------------
HR = [-2147221404], Invalid FORMATETC structure
Failed
filenameA : IMGP2164.jpg
---------------Retrieving file:--------------------
Format: [49330], FileContents
PTD: 0
Aspect: 1
Lindex: 1
Tymed: 13
---------------------------------------------------
HR = [-2147221404], Invalid FORMATETC structure
Failed
filenameA : IMGP2144.jpg
---------------Retrieving file:--------------------
Format: [49330], FileContents
PTD: 0
Aspect: 1
Lindex: 2
Tymed: 13
---------------------------------------------------
HR = [-2147221404], Invalid FORMATETC structure
Failed
[Clipboard Format: RenPrivateFileAttachments ]
[Format: RenPrivateFileAttachments, 49730 ]
[Aspect: 1 ]
[Lindex: -1 ]
[Tymed: 5 ]
[Clipboard Format: FileContents ]
[Format: FileContents, 49330 ]
[Aspect: 1 ]
[Lindex: -1 ]
[Tymed: 5 ]
[Clipboard Format: CF_TEXT ]
[Format: FileContents, 1 ]
[Aspect: 1 ]
[Lindex: -1 ]
[Tymed: 5 ]
[Clipboard Format: CF_UNICODETEXT ]
[Format: FileContents, 13 ]
[Aspect: 1 ]
[Lindex: -1 ]
[Tymed: 5 ]
[Clipboard Format: Ole Private Data ]
[Format: Ole Private Data, 49171 ]
[Aspect: 1 ]
[Lindex: -1 ]
[Tymed: 5 ]
[Clipboard Format: CF_LOCALE ]
[Format: Ole Private Data, 16 ]
[Aspect: 1 ]
[Lindex: -1 ]
[Tymed: 5 ]
[Clipboard Format: CF_OEMTEXT ]
[Format: Ole Private Data, 7 ]
[Aspect: 1 ]
[Lindex: -1 ]
[Tymed: 5 ]
 
W

Wei Lu [MSFT]

Hello Jake,

I am not a Delphi expert so I will try my best to understand what you want
to do. If I am offset, please correct me.

Since I only found the GetClipboardFormatName method in your code, I assume
you copy the attachment from the outlook and then you use your program to
read it.

According to the error message, it seems that Outlook fill differently in
the FORMATETC structure.

I would like to suggest you use a tool from the CodeProject named ClipSpy
which you could check the Clipboard content.

http://www.codeproject.com/clipboard/clipspy.asp

You could use this tool to check the content you copy from Outlook 2000/XP
and Outlook 2003 to see the difference.

Hope this will be some help!

Sincerely,

Wei Lu

Microsoft Online Community Support

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
W

Wei Lu [MSFT]

Hi ,

How is everything going? Please feel free to let me know if you need any
assistance.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jake

Thanks for the follow-up but it appears that 'ClipSpy' doesn't work in
Outlook2003 either. It appears the data format in Outlook2003 has changed.


Getting data form clipboard after multiple Outlook 2003 attachments
selection.
Here is a piece of code, trying to get data from selected file, let say, N
5:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CF_FILECONTENTS = RegisterClipboardFormat(CFSTR_FILECONTENTS);
fetc.cfFormat = CF_FILECONTENTS;
fetc.ptd = 0;
fetc.dwAspect = DVASPECT_CONTENT;
fetc.lindex = 4;
fetc.tymed = TYMED_ISTREAM;

IDataObject GetData(&fetc, &stg) returns the error:

DV_E_FORMATETC - Invalid value for pFormatetc.

In case of

fetc.lindex = -1;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

GetData returns S_OK, but returned data contains only first selected file.

Your help solving this issue is appreciated.

Thanks
 
W

Wei Lu [MSFT]

Hello Jake,

The GetData Method only used for the Windows Clipboard.

So far as I know, I did not find any method to access the Office Clipboard.

Since the Windows Clipboard only could contain one thing once, you could
only get the first selected file.

Sincerely,

Wei Lu

Microsoft Online Community Support

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
J

Jake

I am not sure I understand your answer.

This method worked for all versions except Outlook 2003. Also we are able to
copy multiple image attachments from Outlook 2003 and pasted them from the
clipboard into a Word document successfully. So it would appear to me the
data is there in the clipboard.

Jake
 
W

Wei Lu [MSFT]

Hello Jake,

I understanded. Yes, this issue may caused by the different format of the
clipboard information.

Since this information is undocumented, I will need to consult internally
and I appreciated your patience.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Wei Lu [MSFT]

Hi ,

How is everything going? Please feel free to let me know if you need any
assistance.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jake

Hello,

I have been waiting for a reply from you regarding the clipboard format.
This was your last post.
I understanded. Yes, this issue may caused by the different format of the
clipboard information.

Since this information is undocumented, I will need to consult internally
and I appreciated your patience.

Sincerely,

Wei Lu
 
W

Wei Lu [MSFT]

Hello Jake,

I just checked that whether you have resolved by yourself. Currently, I did
not get the response from internal team. I appreciat your patience.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Wei Lu [MSFT]

Hello Jake,

I did not get the update from internal team.

I appreciate your patience.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jake

Hello Wei,

Yes I have be patient....

However I don't see why it should take so long to get an answer to such a
simple question.

I would appreciate you doing all you can to get someone to provide a
solution.

Thank you.

Jake
 
W

Wei Lu [MSFT]

Hello Jake,

I am sorry that I still did not get the response from the internal group.

Since this issue is about the difference between Office 2003 and ealier
version Office, our internal team may try to find some other resources to
get the information.

Once I get the information, I will provide it as soon as possible. Thank
you for your understanding!

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Wei Lu [MSFT]

Hello Jake,

Since we did not provide direct support for Delphi, we need to reproduce
this issue in a supported language (i.e. C++, Visual Basic 6, VB.NET, or
C#).

Could you provide a sample of the supported language for us to further
troubleshooting?

You could send the sample to me and I will involve other resources to help
you.

To reach me, please remove the ONLINE in my email address.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Wei Lu [MSFT]

Hello Jake,

Could you send me an email so that I can involve other resources to assis
on this issue? We do not need to generate a sample in C++. Thanks!

Sincerely,

Wei Lu

Microsoft Online Community Support

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top