From: Thomas Sondergaard Date: 2003-09-28T19:31:42+09:00 Subject: Re: RubyDotNet and Drag and Drop Apparently there is a need to set the COM ApartmentState to STA Adding this in the first line of the ruby Init_dotnet function makes it go away: System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA; Cheers, Thomas "Wayne Vucenic" wrote in message news:182202853037.20030927220828@netgate.net... > I just heard about RubyDotNet, and it looks really great! > > I did encounter a problem while trying to use drag and drop. (RubyDotNet > r4, Ruby 1.8, .NET 1.1, Windows XP). Here's a stripped down piece of > code that demonstrates the problem: > > require 'dotnet' > > loadLibrary 'System.Windows.Forms' > > form = Form.new > form.topMost = true > form.text = 'Drag and Drop Test' > form.AllowDrop = true; > > Application.Run form > > When I run this I get a "Microsoft .NET Framework" dialog saying "An > unhandled exception has occurred in your application...DragDrop > registration failed" with the following details: > > ************** Exception Text ************** > System.InvalidOperationException: DragDrop registration failed. ---> > System.Threading.ThreadStateException: 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. > at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept) > --- End of inner exception stack trace --- > at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept) > at System.Windows.Forms.Control.OnHandleCreated(EventArgs e) > at System.Windows.Forms.Form.OnHandleCreated(EventArgs e) > at System.Windows.Forms.Control.WmCreate(Message& m) > at System.Windows.Forms.Control.WndProc(Message& m) > at System.Windows.Forms.ScrollableControl.WndProc(Message& m) > at System.Windows.Forms.ContainerControl.WndProc(Message& m) > at System.Windows.Forms.Form.WmCreate(Message& m) > at System.Windows.Forms.Form.WndProc(Message& m) > at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m) > at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m) > at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, > IntPtr wparam, IntPtr lparam) > > Thanks!!! > > Wayne > No Bugs Software > "Ruby and C++ Contract Programming in Silicon Valley" > >