PC Review


Reply
Thread Tools Rate Thread

Clipboard.GetDataObject();

 
 
Max2006
Guest
Posts: n/a
 
      2nd Jul 2008
Hi,

No matter what I have in clipboard Clipboard.GetDataObject(); returns null.
I suspect it might be a problem with Vista or VS2008 IDE debug mode problem?

Is there any way to track why the following statement is always null?

IDataObject iData = Clipboard.GetDataObject();

Thank you,
Max


 
Reply With Quote
 
 
 
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      2nd Jul 2008
Hi Max,

Where do you run this code snippet? Have you tried to run your application
as elevated in Vista? I suspect this issue is caused by the security
enhancement of Vista.

Can you provide detailed steps for me to reproduce it locally? Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(E-Mail Removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Max2006
Guest
Posts: n/a
 
      2nd Jul 2008
Hi Jeffry,

Here is the steps to reproduce the problem:

1) use visual studio 2008 team system on windows vista sp1
2) Run the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AdjustClipboard
{
class Program
{
static void Main(string[] args)
{
IDataObject iData = Clipboard.GetDataObject();

string s = Clipboard.GetData(DataFormats.Text).ToString();
}
}
}


3) you will get null exception!



Thank you for help,
Max



""Jeffrey Tan[MSFT]"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Max,
>
> Where do you run this code snippet? Have you tried to run your application
> as elevated in Vista? I suspect this issue is caused by the security
> enhancement of Vista.
>
> Can you provide detailed steps for me to reproduce it locally? Thanks.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Community Support
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> (E-Mail Removed).
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>

 
Reply With Quote
 
Family Tree Mike
Guest
Posts: n/a
 
      2nd Jul 2008
The documentation on MSDN says you need the [STAThreadAttribute()] on main
to use the call to GetDataObject(). With that change, your code worked fine
for me on Vista (Home Edition).


"Max2006" <(E-Mail Removed)> wrote in message
newsF9CE386-FF3D-4820-95FC-(E-Mail Removed)...
> Hi Jeffry,
>
> Here is the steps to reproduce the problem:
>
> 1) use visual studio 2008 team system on windows vista sp1
> 2) Run the following code:
>
> using System;
> using System.Collections.Generic;
> using System.Linq;
> using System.Text;
> using System.Windows.Forms;
>
> namespace AdjustClipboard
> {
> class Program
> {
> static void Main(string[] args)
> {
> IDataObject iData = Clipboard.GetDataObject();
>
> string s = Clipboard.GetData(DataFormats.Text).ToString();
> }
> }
> }
>
>
> 3) you will get null exception!
>
>
>
> Thank you for help,
> Max
>
>
>
> ""Jeffrey Tan[MSFT]"" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi Max,
>>
>> Where do you run this code snippet? Have you tried to run your
>> application
>> as elevated in Vista? I suspect this issue is caused by the security
>> enhancement of Vista.
>>
>> Can you provide detailed steps for me to reproduce it locally? Thanks.
>>
>> Best regards,
>> Jeffrey Tan
>> Microsoft Online Community Support
>>
>> Delighting our customers is our #1 priority. We welcome your comments and
>> suggestions about how we can improve the support we provide to you.
>> Please
>> feel free to let my manager know what you think of the level of service
>> provided. You can send feedback directly to my manager at:
>> (E-Mail Removed).
>>
>> ==================================================
>> Get notification to my posts through email? Please refer to
>> http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
>> ==================================================
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>


 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      3rd Jul 2008
Hi Max,

Thanks for your feedback, yes, I can reproduce this behavior.

I think "Family Tree Mike" has kindly pointed out the root cause. We need
STAThreadAttribute[] on the Main method, or an exception will throw. This
requirement is documented in the MSDN link below:
http://msdn.microsoft.com/en-us/libr...lipboard.getda
taobject.aspx

Once you added STAThreadAttribute, it should work well. I tested this on my
Vista Enterprise SP1 machine, it works well. Below is the test code:

[STAThread]
static void Main()
{
IDataObject iData = Clipboard.GetDataObject();
string s = Clipboard.GetData(DataFormats.Text).ToString();
MessageBox.Show(s);
}
Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(E-Mail Removed).

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

 
Reply With Quote
 
Max2006
Guest
Posts: n/a
 
      3rd Jul 2008
WOW, That was a neat point. Thank you very much for help

"Family Tree Mike" <(E-Mail Removed)> wrote in message
news:93570042-31B9-4CB9-A7FC-(E-Mail Removed)...
> The documentation on MSDN says you need the [STAThreadAttribute()] on main
> to use the call to GetDataObject(). With that change, your code worked
> fine for me on Vista (Home Edition).
>
>
> "Max2006" <(E-Mail Removed)> wrote in message
> newsF9CE386-FF3D-4820-95FC-(E-Mail Removed)...
>> Hi Jeffry,
>>
>> Here is the steps to reproduce the problem:
>>
>> 1) use visual studio 2008 team system on windows vista sp1
>> 2) Run the following code:
>>
>> using System;
>> using System.Collections.Generic;
>> using System.Linq;
>> using System.Text;
>> using System.Windows.Forms;
>>
>> namespace AdjustClipboard
>> {
>> class Program
>> {
>> static void Main(string[] args)
>> {
>> IDataObject iData = Clipboard.GetDataObject();
>>
>> string s = Clipboard.GetData(DataFormats.Text).ToString();
>> }
>> }
>> }
>>
>>
>> 3) you will get null exception!
>>
>>
>>
>> Thank you for help,
>> Max
>>
>>
>>
>> ""Jeffrey Tan[MSFT]"" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi Max,
>>>
>>> Where do you run this code snippet? Have you tried to run your
>>> application
>>> as elevated in Vista? I suspect this issue is caused by the security
>>> enhancement of Vista.
>>>
>>> Can you provide detailed steps for me to reproduce it locally? Thanks.
>>>
>>> Best regards,
>>> Jeffrey Tan
>>> Microsoft Online Community Support
>>>
>>> Delighting our customers is our #1 priority. We welcome your comments
>>> and
>>> suggestions about how we can improve the support we provide to you.
>>> Please
>>> feel free to let my manager know what you think of the level of service
>>> provided. You can send feedback directly to my manager at:
>>> (E-Mail Removed).
>>>
>>> ==================================================
>>> Get notification to my posts through email? Please refer to
>>> http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
>>> ==================================================
>>> This posting is provided "AS IS" with no warranties, and confers no
>>> rights.
>>>

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FatalExecutionEngineError calling Clipboard.GetDataObject().GetData() with EnhancedMetafile nagar@community.nospam Microsoft Dot NET 5 16th Aug 2007 06:06 AM
Transfer clipboard from Task pane clipboard(office?) content to Excel (windows?) clipboard? tskogstrom Microsoft Excel Programming 2 6th Mar 2007 12:50 PM
Clipboard gets empty by itself, cleared clipboard, copy paste doesn't work, outlook clears clipboard, problems with clipboard - possible solution Jens Hoerburger Microsoft Outlook 0 24th Aug 2006 02:44 PM
Problems with clipboard : system.runtime.interopservices : The requested clipboard operation failed Dennis Microsoft C# .NET 0 5th Apr 2004 06:43 PM
clipboard operation GetDataObject fails Stefan Kiryazov Microsoft Dot NET 1 20th Dec 2003 01:05 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:59 PM.