By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,526 Members | 2,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,526 IT Pros & Developers. It's quick & easy.

Outlook automation using managed code

P: n/a
Max
Hi,

I would like to have a button and a combo box with options to select various versions of Microsoft Outlook: 2002, 2003.
The user selects the email client and clicks the button. The only things happening will be: a new email is created and some text is
placed in the body, then the email window is displayed. The user can close the window or select some recipients and send the
message.
I would like some info on how to do this correctly. Is the best way to do this using early binding or late binding?

If I work with early binding, then what is the correct way of doing this? Right now I installed the Office 2003 PIAs from the link
below:

http://www.microsoft.com/downloads/d...displaylang=en

and I added a reference to Microsoft Outlook 11.0 Object Library to my project. Was this the right way to do it? Is installing the
above the same as getting the Office 2003 PIAs through the Office 2003 setup feature? I am beginning to think that it is not and I
have to manually remove these from the GAC and do a repair and get them through Office 2003.

For what I need to do which is just open an email and put some text in it then let the user continue, will the 2003 version of
Outlook PIA be enough to support both MS Outlook 2002 and 2003 or do I have to rely on late binding? The setup project is adding
dependencies to the dlls used and they go with the application. Is this the right way to do it or do I need to ask the user to
download the PIA's from the link above as well?

Thanks,
Max

Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
You'll need to use late binding. You can use early binding, but then you'll
have to bind to all the different versions.

Personally, I've found binding to Outlook (and other Office app) stuff to be
a pain in the ass because of the different versions and the massive changes
that happen from version to version. It tends to require very different code
for each version which can be a big pain.

Pete

"Max" <ma******@yahoo.com> wrote in message
news:Ok*************@tk2msftngp13.phx.gbl...
Hi,

I would like to have a button and a combo box with options to select
various versions of Microsoft Outlook: 2002, 2003.
The user selects the email client and clicks the button. The only things
happening will be: a new email is created and some text is placed in the
body, then the email window is displayed. The user can close the window or
select some recipients and send the message.
I would like some info on how to do this correctly. Is the best way to do
this using early binding or late binding?

If I work with early binding, then what is the correct way of doing this?
Right now I installed the Office 2003 PIAs from the link below:

http://www.microsoft.com/downloads/d...displaylang=en

and I added a reference to Microsoft Outlook 11.0 Object Library to my
project. Was this the right way to do it? Is installing the above the same
as getting the Office 2003 PIAs through the Office 2003 setup feature? I
am beginning to think that it is not and I have to manually remove these
from the GAC and do a repair and get them through Office 2003.

For what I need to do which is just open an email and put some text in it
then let the user continue, will the 2003 version of Outlook PIA be enough
to support both MS Outlook 2002 and 2003 or do I have to rely on late
binding? The setup project is adding dependencies to the dlls used and
they go with the application. Is this the right way to do it or do I need
to ask the user to download the PIA's from the link above as well?

Thanks,
Max

Nov 17 '05 #2

P: n/a
Max
Thanks for your reply Pete.

I have successfully used late binding to automate Outlook 2000,2002,2003. However I did not have any event handlers for catching
when the user closed the email window or sent the email and hence Outlook remained in memory since I did not clean up :)
Now that I'm trying to work my way through Inspectors and Creating Delegates I'm getting run time errors....

"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message news:HJ********************@giganews.com...
You'll need to use late binding. You can use early binding, but then you'll have to bind to all the different versions.

Personally, I've found binding to Outlook (and other Office app) stuff to be a pain in the ass because of the different versions
and the massive changes that happen from version to version. It tends to require very different code for each version which can be
a big pain.

Pete

"Max" <ma******@yahoo.com> wrote in message news:Ok*************@tk2msftngp13.phx.gbl...
Hi,

I would like to have a button and a combo box with options to select various versions of Microsoft Outlook: 2002, 2003.
The user selects the email client and clicks the button. The only things happening will be: a new email is created and some text
is placed in the body, then the email window is displayed. The user can close the window or select some recipients and send the
message.
I would like some info on how to do this correctly. Is the best way to do this using early binding or late binding?

If I work with early binding, then what is the correct way of doing this? Right now I installed the Office 2003 PIAs from the
link below:

http://www.microsoft.com/downloads/d...displaylang=en

and I added a reference to Microsoft Outlook 11.0 Object Library to my project. Was this the right way to do it? Is installing
the above the same as getting the Office 2003 PIAs through the Office 2003 setup feature? I am beginning to think that it is not
and I have to manually remove these from the GAC and do a repair and get them through Office 2003.

For what I need to do which is just open an email and put some text in it then let the user continue, will the 2003 version of
Outlook PIA be enough to support both MS Outlook 2002 and 2003 or do I have to rely on late binding? The setup project is adding
dependencies to the dlls used and they go with the application. Is this the right way to do it or do I need to ask the user to
download the PIA's from the link above as well?

Thanks,
Max



Nov 17 '05 #3

P: n/a
Max
The error I'm getting at runtime says:

System.ArgumentException: Error binding to target method.
at System.Delegate.InternalCreate(Object target, String method, Boolean ignoreCase)
at System.Delegate.CreateDelegate(Type type, Object target, String method)

and it happens on the last line of this code:

Expand|Select|Wrap|Line Numbers
  1. Type oType = Type.GetTypeFromProgID("Outlook.Application");
  2. oApp = Activator.CreateInstance(oType);
  3.  
  4. oInspectors = oApp.GetType().GetProperty("Inspectors").GetValue(oApp, null);
  5.  
  6. e_NewInspector = oInspectors.GetType().GetEvent("NewInspector");
  7. d_NewEventDelegate = Delegate.CreateDelegate(e_NewInspector.EventHandlerType,
  8. this, "Inspectors_NewInspector");
  9.  
The debugger loads the assemblies from the GAC. Is there anything wrong with that?

Loaded 'c:\windows\assembly\gac\microsoft.office.interop. outlook\11.0.0.0__71e9bce111e9429c\microsoft.offic e.interop.outlook.dll',
No symbols loaded.
Loaded 'c:\windows\assembly\gac\office\11.0.0.0__71e9bce1 11e9429c\office.dll', No symbols loaded.


"Max" <ma******@yahoo.com> wrote in message news:eW*************@TK2MSFTNGP15.phx.gbl...
Thanks for your reply Pete.

I have successfully used late binding to automate Outlook 2000,2002,2003. However I did not have any event handlers for catching
when the user closed the email window or sent the email and hence Outlook remained in memory since I did not clean up :)
Now that I'm trying to work my way through Inspectors and Creating Delegates I'm getting run time errors....

"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message news:HJ********************@giganews.com...
You'll need to use late binding. You can use early binding, but then you'll have to bind to all the different versions.

Personally, I've found binding to Outlook (and other Office app) stuff to be a pain in the ass because of the different versions
and the massive changes that happen from version to version. It tends to require very different code for each version which can
be a big pain.

Pete

"Max" <ma******@yahoo.com> wrote in message news:Ok*************@tk2msftngp13.phx.gbl...
Hi,

I would like to have a button and a combo box with options to select various versions of Microsoft Outlook: 2002, 2003.
The user selects the email client and clicks the button. The only things happening will be: a new email is created and some text
is placed in the body, then the email window is displayed. The user can close the window or select some recipients and send the
message.
I would like some info on how to do this correctly. Is the best way to do this using early binding or late binding?

If I work with early binding, then what is the correct way of doing this? Right now I installed the Office 2003 PIAs from the
link below:

http://www.microsoft.com/downloads/d...displaylang=en

and I added a reference to Microsoft Outlook 11.0 Object Library to my project. Was this the right way to do it? Is installing
the above the same as getting the Office 2003 PIAs through the Office 2003 setup feature? I am beginning to think that it is not
and I have to manually remove these from the GAC and do a repair and get them through Office 2003.

For what I need to do which is just open an email and put some text in it then let the user continue, will the 2003 version of
Outlook PIA be enough to support both MS Outlook 2002 and 2003 or do I have to rely on late binding? The setup project is adding
dependencies to the dlls used and they go with the application. Is this the right way to do it or do I need to ask the user to
download the PIA's from the link above as well?

Thanks,
Max



Nov 17 '05 #4

P: n/a
Honestly, it would be hard to say. The last time I used outlook was a couple
versions back (wrote an app that notified me of new mail with a voice
synthesizer that spoke the name and subject of the e-mail).

The assemblies you're using are definitely different than the ones I used. I
don't recall creating any delegates, per se. The only thing I did was
subscribe to the NewMailEventHandler which was as simple as something like
this:

applicationObject.Application.NewMail +=
new
Outlook.ApplicationEvents_NewMailEventHandler(Appl ication_NewMail);

From my version of the API, I would think that all you'd have to do is:

oApp.Application.Inspectors.NewInspector +=
Outlook.InspectorEvents_NewInspectorEventHandler(M y_NewInspector)

and then add an event handler called My_NewInspector.

Now, maybe I did mine differently than you're doing yours.

I had a class that implemented Extensibility.IDTExtensibility2. It also had
a ProgID and Guid and was registered for COM interop.

Honestly I don't remember the specifics. I wrote this thing back in 2003.

If you'd like to look at the code, though, you can download it here:
http://www.petedavis.net/downloads/SpokenMail.zip

Pete
"Max" <ma******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
The error I'm getting at runtime says:

System.ArgumentException: Error binding to target method.
at System.Delegate.InternalCreate(Object target, String method, Boolean
ignoreCase)
at System.Delegate.CreateDelegate(Type type, Object target, String
method)

and it happens on the last line of this code:

Expand|Select|Wrap|Line Numbers
  1.  Type oType = Type.GetTypeFromProgID("Outlook.Application");
  2.  oApp = Activator.CreateInstance(oType);
  3.  oInspectors = oApp.GetType().GetProperty("Inspectors").GetValue(oApp,
  4.  null);
  5.  e_NewInspector = oInspectors.GetType().GetEvent("NewInspector");
  6.  d_NewEventDelegate =
  7.  Delegate.CreateDelegate(e_NewInspector.EventHandlerType,
  8.        this, "Inspectors_NewInspector");
  9.  

The debugger loads the assemblies from the GAC. Is there anything wrong
with that?

Loaded
'c:\windows\assembly\gac\microsoft.office.interop. outlook\11.0.0.0__71e9bce111e9429c\microsoft.offic e.interop.outlook.dll',
No symbols loaded.
Loaded
'c:\windows\assembly\gac\office\11.0.0.0__71e9bce1 11e9429c\office.dll', No
symbols loaded.


"Max" <ma******@yahoo.com> wrote in message
news:eW*************@TK2MSFTNGP15.phx.gbl...
Thanks for your reply Pete.

I have successfully used late binding to automate Outlook 2000,2002,2003.
However I did not have any event handlers for catching when the user
closed the email window or sent the email and hence Outlook remained in
memory since I did not clean up :)
Now that I'm trying to work my way through Inspectors and Creating
Delegates I'm getting run time errors....

"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message
news:HJ********************@giganews.com...
You'll need to use late binding. You can use early binding, but then
you'll have to bind to all the different versions.

Personally, I've found binding to Outlook (and other Office app) stuff
to be a pain in the ass because of the different versions and the
massive changes that happen from version to version. It tends to require
very different code for each version which can be a big pain.

Pete

"Max" <ma******@yahoo.com> wrote in message
news:Ok*************@tk2msftngp13.phx.gbl...
Hi,

I would like to have a button and a combo box with options to select
various versions of Microsoft Outlook: 2002, 2003.
The user selects the email client and clicks the button. The only
things happening will be: a new email is created and some text is
placed in the body, then the email window is displayed. The user can
close the window or select some recipients and send the message.
I would like some info on how to do this correctly. Is the best way to
do this using early binding or late binding?

If I work with early binding, then what is the correct way of doing
this? Right now I installed the Office 2003 PIAs from the link below:

http://www.microsoft.com/downloads/d...displaylang=en

and I added a reference to Microsoft Outlook 11.0 Object Library to my
project. Was this the right way to do it? Is installing the above the
same as getting the Office 2003 PIAs through the Office 2003 setup
feature? I am beginning to think that it is not and I have to manually
remove these from the GAC and do a repair and get them through Office
2003.

For what I need to do which is just open an email and put some text in
it then let the user continue, will the 2003 version of Outlook PIA be
enough to support both MS Outlook 2002 and 2003 or do I have to rely on
late binding? The setup project is adding dependencies to the dlls used
and they go with the application. Is this the right way to do it or do
I need to ask the user to download the PIA's from the link above as
well?

Thanks,
Max

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.