HiPhiSch Posted January 30, 2009 Share Posted January 30, 2009 Hi all! I tried to access the Clipboard in the OnRender section with this: IDataObject idat; lock(this) { idat = Clipboard.GetDataObject(); } // idat == null <- this happens every time I used a try block before, the simplified code is just for testing. There is no exception thrown, but I always just get the null, no matter what is stored inside of the clipboard. I also included a demand for UIPermission including AllClipboard. This does not help. I am using VS2008 pro if that matters. Is it somehow possible to read content from the clipboard? I hope you can help me out. Quote Link to comment Share on other sites More sharing options...
Simon Brown Posted January 30, 2009 Share Posted January 30, 2009 Try doing so from either the dialog or OnSetRenderInfo() - i've had problems before accessing the clipboard while another thread in the process is running. Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted January 30, 2009 Share Posted January 30, 2009 You can only access the clipboard from an STA thread. I ran into this with some refactoring of the regular Edit->Paste command, in fact. IDataObject idat = null; Exception threadEx = null; Thread staThread = new Thread( delegate { try { idat = Clipboard.GetDataObject(); } catch (Exception ex) { threadEx = ex; } }); staThread.SetApartmentState(ApartmentState.STA); staThread.Start(); staThread.Join(); // at this point either you have clipboard data or an exception You probably also have to query the existence of clipboard data within that STA thread, btw. And, also, don't do this from OnRender(). Do it within OnSetRenderInfo(). Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
BoltBait Posted January 30, 2009 Share Posted January 30, 2009 Man! I've been wondering about this for a while now... Good info. Thanks! Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
Rick Brewster Posted January 31, 2009 Share Posted January 31, 2009 Yeah the clipboard is tied in to some COM voodoo. COM objects are tied in to STA vs. MTA stuff. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
HiPhiSch Posted February 1, 2009 Author Share Posted February 1, 2009 Thanks a million! I will try it out Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.