Drag and drop attachment in outlook addin

N

nitwalke

Hi All,

I have created outlook addin for outlook 2003 in vsto-2008. When I hav
tried to allow property 'allowDrag' to textbox it gives runtim
exception "dragdrop registration did not succeed". I have searched o
net, got suggestion to use threading.

Thread t = new Thread(new ThreadStart(ShowForm));
t.SetApartmentState(ApartmentState.STA);
t.Start();

public void ShowForm()
{

form.ShowDialog();
form.Dispose();
}

Drag problem solved using thread but it give other problem in m
application as follows
a) When I right click on context menu then form disappear.
b) Some time application hangs...

Can I solve this problem without using thread? Because handling threa
will almost change my design.

Regards,
Ni
 
K

Ken Slovak - [MVP - Outlook]

Are you trying to use the Outlook object model from a background thread?
That's not supported and will crash or hang Outlook. You have to marshal
that background thread to the main process thread if you are using the
object model.
 
N

nitwalke

Thanks Ken for replay.
I am not interested to use thread. I want to know, Can DragDro
registration will possible without using thread.I got following erro
while registering DragDrop event for text box.
"System.InvalidOperationException: DragDrop registration did no
succeed. ---> System.Threading.ThreadStateException: Current thread mus
be set to single thread apartment (STA) mode before OLE calls can b
made. Ensure that your Main function has STAThreadAttribute marked o
it."

I searched on net and got threading solution. But Can we solve thi
problem without using thread?

'Ken Slovak - [MVP - Outlook said:
;95211']Are you trying to use the Outlook object model from a backgroun
thread?
That's not supported and will crash or hang Outlook. You have t
marshal
that background thread to the main process thread if you are using the
object model.




message
 
N

nitwalke

I will give details about my project.
In ThisAddIn class..

[STAThread]
private void NewButtonClick()
{
Form frm = new Form();
frm.ShowDialog();
}

and in form class.
I have created textbox and set AllowDrop=True;
it gives following error

System.InvalidOperationException: DragDrop registration did no
succeed. ---> System.Threading.ThreadStateException: Current thread mus
be set to single thread apartment (STA) mode before OLE calls can b
made. Ensure that your Main function has STAThreadAttribute marked o
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)
a
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message
m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int3
msg, IntPtr wparam, IntPtr lparam)

I put [STAThread] above startup method

[STAThread]
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top