开发者

DataObject GetDataPresent(format) returns true, and GetData(format) return null

Here's the full setup for what I'm trying to do: We have an ActiveX control on a web page (ugh), and we want to save it's view to a image, and post that to the server. As this ActiveX control does not support that directly, we have to take a slightly more round-about method.

The platform: IE8, Windows 7, UAC/IE Protected mode off.

This method is sending the ActiveX control a message to copy its c开发者_开发百科urrent view to a clipboard. Once it has done that, we launch an application via a protocol handler (e.g. app:clipboard/blah/blah). This program is supposed to grab the data off the clipboard get it to the right format (jpeg), and this post it to a URL.

The code I'm using for testing is this:

var dataObject = Clipboard.GetDataObject();
Trace.WriteLine("Data formats on clipboard: " + dataObject.GetFormats().Aggregate(" ",(s,v)=>s+v+ " "));
foreach (var fmt in dataObject.GetFormats())
{
    Trace.WriteLine("GetDataPresent on " + fmt + ": " + dataObject.GetDataPresent(fmt));
    Trace.WriteLine("GetData on " + fmt +": " + !(dataObject.GetData(fmt,true)==null));
}

Which results in the following output when run from the handler:

Data formats on clipboard:  EnhancedMetafile MetaFilePict 
GetDataPresent on EnhancedMetafile: True
GetData on EnhancedMetafile is null: True
GetDataPresent on MetaFilePict: True
GetData on MetaFilePict is null: True

Now, I am at an absolute loss as to why GetDataPresent returns true, and then GetData on the same format string returns null. For an added bonus, I know the data is making it to the clipboard, as I can turn around and go into Paint.Net and paste, and there's my image.

Any one run into something similar?


I have no clue what was going on with the managed API. I ended up just p/invoking the WinAPI for the functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜