NI Home > Community > NI Discussion Forums

LabVIEW

Reply
Member
imdmil
Posts: 1
0 Kudos

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.
Active Participant
Lycangeek
Posts: 560

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

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.