Bear23

I have posted a question in reguards to creating a button in the new mail form. the button is created and looks great. however no matter what code I place in the click even nothing works.

I tried having the button open a form, I tried using the outlook snippets from Microsoft to insert an attachment and nothing seems to work. the only thing i can get it to do is open a messagebox.

Also I cannot get another machine I have vs 2005 on to debug my outlook code like my pc. I have no idea what my pc has that the other doesn't any ideas. When I go to the com addin i notice that I have to manually set the trust rights in the control panel. not sure why my pc does this automatically.

Can anyone help me out on these issues



Re: Visual Studio Tools for Office outlook button not opening anything

perpetual_dream

Put your code within the button on click between try catch block. This way you'll have a better idea about what is taking place. outlook handles unhandled errors and doesn't show any error messages.

Code Snippet

try

//your code

catch ex as exception

msgbox(Ex.message")

end try





Re: Visual Studio Tools for Office outlook button not opening anything

Bear23

I will try, i know on the other machine when I hit the run button it runs but I cannot debug,etc





Re: Visual Studio Tools for Office outlook button not opening anything

Bear23

ok when i try and open a form I get this error:

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. This exception is only raised if a debugger is attacthed to the process.

now if I try this code:

object obj = Activator.CreateInstance(Type.GetTypeFromProgID("MSComDlg.CommonDialog"));

MSComDlg.CommonDialog box= new MSComDlg.CommonDialog();

box.ShowOpen();

I get the following error:

The common dialog function failed during initialization. This error often occurs when insufficient memory is available.

I have 2 gb.

What I am trying to do is 2 things.

1. Be able to open a c# form.

2. Open a dialog box where the user can select a file and the name of the selected files is inserted into the the email message where there cursor is located.





Re: Visual Studio Tools for Office outlook button not opening anything

Bear23

any thoughts



Re: Visual Studio Tools for Office outlook button not opening anything

Andrew Cherry [MSFT]

It appears as if you're trying to create the Windows Form on a background thread. Winforms only behaves well on the foreground thread; I could be completely wrong, but based on the STA error you're seeing, that's my first guess. The Common Dialog may have a similar limitation.

Regarding nothing happening in the events you're firing, Outlook is somewhat aggressive in releasing references; it's possible your event handler is being detached due to the reference to the CommandBar going away. Some more information about your scenario may enable us to give you better help.

Andrew