From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error 1172calling .NET dll...must set dll to single thread

I receive the following when trying to call a simple dll from LV.  Works fine from a VB.NET GUI.
Error 1172 occurred at Error calling method Clipboard_Test.Clipboard.Test.Copy of ObjectId handle: 0x7A8110C for obj 0x7E[Clipboard_Test.Clipboard.Test] in domain [LabVIEW Domain for Run] and thread 3272 >> Exception has been thrown by the target of an invocation. >> The current thread must set to Single Thread Apartment (STA) mode before OLE calls can be made.  Ensure that your Main function has STAThreadAttribute marked on it. in ClipboardTest.vi
 
How do I set the dll to be single threaded to satisfy the OLE requirement.  I can place the STAThread attribute before both subs, but still get the error from LV.  I get a builed error if I try to place it in front of the class.  I am new to .NET so I could use some help with this.
 
Ideally, I am trying to place a copy of an Excel Chart onto the Clipboard and save it as a METAFILE to later paste into PowerPoint.  Am really stuck on this because of all the new syntax and terms.
0 Kudos
Message 1 of 2
(3,587 Views)
The STA apartment is the "Single Threaded Apartment" and is usually the same thing as saying "the UI thread". So the object you have requires that any calls to it must be on the UI thread. To do this, go to the VI properties (right click on the VI icon to get to the properties) and select the Execution from the pull down. From this panel you can force the VI to run on a specific thread - in this case the UI thread. Do this on any VI which calls this object. 
Message 2 of 2
(3,578 Views)