By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,563 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,563 IT Pros & Developers. It's quick & easy.

Clipboard.GetDataObject();

P: n/a
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
Jul 2 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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:
ms****@microsoft.com.

==================================================
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.

Jul 2 '08 #2

P: n/a
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]"" <je***@online.microsoft.comwrote in message
news:vu**************@TK2MSFTNGHUB02.phx.gbl...
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:
ms****@microsoft.com.

==================================================
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.
Jul 2 '08 #3

P: n/a
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" <al*******@newsgroup.nospamwrote in message
news:DF**********************************@microsof t.com...
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]"" <je***@online.microsoft.comwrote in message
news:vu**************@TK2MSFTNGHUB02.phx.gbl...
>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:
ms****@microsoft.com.

================================================= =
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.
Jul 2 '08 #4

P: n/a
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:
ms****@microsoft.com.

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

Jul 3 '08 #5

P: n/a
WOW, That was a neat point. Thank you very much for help

"Family Tree Mike" <Fa************@ThisOldHouse.comwrote in message
news:93**********************************@microsof t.com...
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" <al*******@newsgroup.nospamwrote in message
news:DF**********************************@microsof t.com...
>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]"" <je***@online.microsoft.comwrote in message
news:vu**************@TK2MSFTNGHUB02.phx.gbl...
>>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:
ms****@microsoft.com.

================================================ ==
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.
Jul 3 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.