Jump to content

.NET Drag Drop error


dcribeiro

Recommended Posts

Hi all.


 


I am trying to call a VB .NET application develloped in my company.


The Construtor node returns no errors.


However when I use the Invoke Node to call the Show() method, the following error appear: "DragDrop registration did not succeed"


 


post-34903-0-90679400-1424991616.png


 


The application I am trying to call uses drag and drop menus.


But, shouldn't LabVIEW be able to let those run?


Is there a work arround for this?


 


 


I am using LabVIEW 2014 32-bits and .NET framework 4.5.


 


Thanks in advance for all the help.


 


Regards,


Diogo Ribeiro


Link to comment

 

Hi all.

 

I am trying to call a VB .NET application develloped in my company.

The Construtor node returns no errors.

However when I use the Invoke Node to call the Show() method, the following error appear: "DragDrop registration did not succeed"

 

attachicon.gifDragDrop_error.png

 

The application I am trying to call uses drag and drop menus.

But, shouldn't LabVIEW be able to let those run?

Is there a work arround for this?

 

 

I am using LabVIEW 2014 32-bits and .NET framework 4.5.

 

Thanks in advance for all the help.

 

Regards,

Diogo Ribeiro

 

 

By application and your description I presume you mean instantiating an instance of the particular Form that you are showing?

 

Or are you calling the static Main method in the (commonly named) Program class in order to start-up the message pump in order to monitor WND messages?

Link to comment

By application and your description I presume you mean instantiating an instance of the particular Form that you are showing?

 

Or are you calling the static Main method in the (commonly named) Program class in order to start-up the message pump in order to monitor WND messages?

 

Yes, I am trying to call an instance of a Form (the main menu of the application), using the method Show(). The Form is not created before the invoke of the method and I want it to show up, so that I can use through LV.

It indeed shows up (not completely, the menu with the drag and drop capabilities enabled does not show), if I press continue in the mentioned error. 

I have tried this approach with success for a different application that does not have any drag and drop menus.

 

Here are some more details about the error:

 

************** Exception Text **************

System.InvalidOperationException: DragDrop registration did not succeed. ---> System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.

at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)

 
 
This error does not show up when I start the application through the SO windows menu directly (as a standalone application).
 
Any ideas on the cause of the problem?
 
Thanks for all the help.
Diogo Ribeiro
Link to comment

Hi,

 

************* Exception Text **************

System.InvalidOperationException: DragDrop registration did not succeed. ---> System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.
at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)

 
 
This error does not show up when I start the application through the SO windows menu directly (as a standalone application).

 

When you run a standalone application, your Form's constructor and the other methods all run in the same thread.

 

However, LabVIEW automatically switches between different threads to run your code. You will get a .NET exception if your Form is accessed from the "wrong" thread.

 

See http://stackoverflow.com/questions/6373645/c-sharp-winforms-how-to-set-main-function-stathreadattribute to get started.

Link to comment

Hi,

 

 

When you run a standalone application, your Form's constructor and the other methods all run in the same thread.

 

However, LabVIEW automatically switches between different threads to run your code. You will get a .NET exception if your Form is accessed from the "wrong" thread.

 

See http://stackoverflow.com/questions/6373645/c-sharp-winforms-how-to-set-main-function-stathreadattribute to get started.

 

Thanks for pointing me in the right direction.

 

It was indeed a thread problem. Since LabVIEW by default uses a multi-thread system (MTA) and Windows Forms need a single-thread system (STA).

 

After some time trying to force, inside the VB code, the thread be an STA.

I found a much simpler solutions in this topic: http://forums.ni.com/t5/Measurement-Studio-for-NET/Calling-net-dll-in-Labview/td-p/803084

In the 1st response by the user nickb.

So by changing the way LabVIEW calls the .NET application in the LabVIEW VI execution properties (change it to "user interface"), my application can now run without any errors.

NickB11-04,%2007_38_27.png

 

Thanks to everyone.

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.