Clippboard access library

Discussion in 'Additional Libraries' started by agraham, Jun 1, 2008.

  1. agraham

    agraham Expert Licensed User

    This small library provides access to the clipboard. It is very simple so the help is in the demo app. Requires .NET 2.0 and should run on both device and desktop. The clipboard.cs source file is supplied for merging the dll. Put it in the Basic4ppc Desktop\Libraries folder.

    EDIT :- It appears that this library will only operate correctly when in an optimised compiled app due to what seems to be a threading issue in the IDE and legacy compiled apps.

    Attached Files:

    Last edited: Jun 4, 2008
  2. BjornF

    BjornF Active Member Licensed User

    Thank you Andrew, very nice ! :sign0188:

    Best wishes / Björn
  3. BjornF

    BjornF Active Member Licensed User

    Sorry Andrew, despite it being very simple I still have problems with it ;)

    In the attached program I can copy the content of a richtextbox with no problems. When I try to do the same from a "normal" textbox I get an error message however. Does this mean that only objects added from a .dll count as objects for the clipboard dll?

    all the best / Björn

    Attached Files:

  4. agraham

    agraham Expert Licensed User

    I think it is some obscure threading problem as your code seems to work fine when optimised compiled and and my demo worked in the IDE when I was testing.

    The IDE error implies that textbox1.text is null (which is not the case) however if you continue after the error it now works OK. It also works if you copy the RTF first! If I legacy compile both my demo and your code I get this error :

    "Current thread must be set to single thread apartment mode before OLE calls can be made. Ensure that your Main function has STA ThreadAttribute marked on it."

    This is required as the clipboard in .NET calls the native clipboard code which is a COM object which needs an STA host. However Erel has told me that Basic4ppc IS now STA threaded (which is why I couldn't produce this library and the WebBrowser before as both are COM objects needing STA) so I have no idea why it is throwing this error.

    Perhaps Erel can shed some light on this if he reads this!

    The RichTextTextbox has a workaround for this threading problem, which I thought had now gone away with the change in threading for B4ppc so I will try to to produce a version of the clipboard library incorporating this workaround.
  5. BjornF

    BjornF Active Member Licensed User

    Thank you for explaining that - I couldn't understand what the error was about... / Björn
  6. agraham

    agraham Expert Licensed User

    I'm sorry Björn but there seems to be a fundamental incompatibility between the .NET clipboard object and both the IDE and legacy compiler on both desktop and device. While things work as I expect when optimised compiling they don't otherwise. I can't even get the workaround that I used in RichTextDesktop to work in this library while it still seems to work fine in the RichTextDesktop libray :confused:

    It looks like this is a device and desktop optimised compile library only.
  7. BjornF

    BjornF Active Member Licensed User

    Dear Andrew, thank you for looking into it.

    The most important thing is that it does work in the optimised, compiled version. Perhaps we can hope for a new compiler for the IDE :)

    all the best / Björn
  8. Erel

    Erel Administrator Staff Member Licensed User

    The thread which runs the code in the IDE is set to "single thread apartment".
    Maybe the problem is caused due to the fact that there is another thread (the main thread in the IDE) that is STA in the same process.
    For now you will only be able to use this library with the optimized compiler.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice