Office XP Add-In

B

brianpmccullough

Hello,

I need to develop an Office XP COM Add-In that needs to extract the message
headers from an original email and forward these headers along in another
email to a specified email address. A few questions (I have not developed an
Office/COM Add In before):

1. I come from a developer background, so I am comfortable working with
most development environments and languages (VB, C#, etc). What tools are
available for me to use to develop this COM Add In?

2. I have read about using "Office XP Developer", but I cannot get the
software loaded b/c I need a "Windows Component Update" disk, which I do not
have. Anyone know where to find this?

3. I have read that you could create the COM Add In using the VB6 "Addin"
project template. I started doing this the other day and was progressing
fine, but after trying to get the "COM Add In" project template (which comes
with Office XP Developer) installed, I messed something up and now I don't
see all my Office applications in the "Designer" item within my project. Now
I only see "Visual Studio" and "Excel". What controls what is displayed in
this list? I used to have Outlook available to me, and no longer do?

4. Since my COM Add In will be interacting with the original message's
headers, I have found that the only way to access these is through CDO. When
I try to access them in a Macro, I get a security dialog prompting to allow
access to the running code. If I create my COM Add In, is there a way to
digitally sign it such that Outlook trusts the code executing within it?

I know this is alot and could take up several postings, but any help is
appreciated!!
 
K

Ken Slovak - [MVP - Outlook]

Answers inline.




brianpmccullough said:
Hello,

I need to develop an Office XP COM Add-In that needs to extract the
message
headers from an original email and forward these headers along in another
email to a specified email address. A few questions (I have not developed
an
Office/COM Add In before):

1. I come from a developer background, so I am comfortable working with
most development environments and languages (VB, C#, etc). What tools are
available for me to use to develop this COM Add In?

[KS] You can use VB6 or VS.NET for this. I probably would not recommend
using Office XP Developer. In general, for earlier versions of Outlook I
wouldn't expect necessarily that the pre-requisites for a .NET addin would
be installed. That would be the Framework, the PIA's, Extensibility.DLL,
possibly the stdole.dll interop component, and a couple of KB fixes. In that
case, unless you plan to deploy over a network or a CD or DVD, that means
your users will need to download those things. I usually use VB 6 because it
doesn't require all that stuff.
2. I have read about using "Office XP Developer", but I cannot get the
software loaded b/c I need a "Windows Component Update" disk, which I do
not
have. Anyone know where to find this?

[KS] Office XP Developer is no longer supported. Most of us never bothered
with it, so your online support will be limited.
3. I have read that you could create the COM Add In using the VB6 "Addin"
project template. I started doing this the other day and was progressing
fine, but after trying to get the "COM Add In" project template (which
comes
with Office XP Developer) installed, I messed something up and now I don't
see all my Office applications in the "Designer" item within my project.
Now
I only see "Visual Studio" and "Excel". What controls what is displayed
in
this list? I used to have Outlook available to me, and no longer do?

[KS] No idea. I'd probably try to reinstall VS 6 to fix it.
4. Since my COM Add In will be interacting with the original message's
headers, I have found that the only way to access these is through CDO.
When
I try to access them in a Macro, I get a security dialog prompting to
allow
access to the running code. If I create my COM Add In, is there a way to
digitally sign it such that Outlook trusts the code executing within it?

[KS] CDO is not supported for .NET usage. It is also considered not secure
by Outlook so it's limited and fires those security prompts. Code signing
will not help with that, and Outlook 2002 doesn't implicitly trust COM
addins as Outlook 2003 and 2007 do, so your options for the security are
limited. See http://www.outlookcode.com/d/sec.htm for those options. I
personally use Redemption to avoid the security prompts.
 
B

Brian McCullough

Ken,

Thanks so much for your help and sorry for the multi-post, but I didn't
realize there was COM-Add In specific group and after posting the original
to the .vba group, I thought the questions were better suited for this
group! I frequent newsgroups often and understand that the multi-post was
not the best thing to do, but thought I had a better shot at getting my
stuff answered in this group.

In any event, for all the same reasons you discussed below, I also am not
sure about using .NET for creation of my AddIn. There are too many
dependencies (between the PIA, .NET Framework, etc.) to take a chance with
this. I think I have decided to create this in VB6.

That being said, when I try to use the Add In project template, I am still
not seeing Outlook available to me in the Application listing in the
Designer. I only have the following listed:

Microsoft Visio
Microsoft Word
Visual Basic
Visual Basic for Applications IDE


I spent the weekend trying to re-install everything and I keep seeing the
same list in the Add In Designer UI. What controls what is displayed in
this list? Does it pull this information from the Registry? Again, at one
point I did have all the Office applications available to me (i.e. Outlook,
Excel, PowerPoint, Access, etc), but now only Visio and Word. I even went
so far as to create a VPC of Windows XP. Then installed Office XP. Then I
installed Visual Basic 6 (Enterprise Edition). On my VPC I am only seeing
these few items available to me in my Designer.

If I cannot get the Designer to work correctly for me, and I understand this
correctly, this information is only needed for the registration of the Add
In during installation. Is it possible to create the Add In and without
using the Add In project template (and therefore, not get the Designer),
then handle the registration of this Add In during the installation
procedures (.msi)? For example, on the Microsoft site they have the
following article published:
http://msdn2.microsoft.com/en-us/library/aa140126(office.10).aspx (which is
written for Outlook 2000, but from what I understand, the concepts still
apply in Outlook XP). In this article, they do not use the Add In project
template, but they don't talk about how to deploy the Add In. How would you
register the Add In during deployment such that users did not have to
manually configure the Add In (i.e. they only need to run the .msi)??

Thanks again for your help!!!!

-Brian McCullough




Ken Slovak - said:
Answers inline.




brianpmccullough said:
Hello,

I need to develop an Office XP COM Add-In that needs to extract the
message
headers from an original email and forward these headers along in another
email to a specified email address. A few questions (I have not
developed an
Office/COM Add In before):

1. I come from a developer background, so I am comfortable working with
most development environments and languages (VB, C#, etc). What tools
are
available for me to use to develop this COM Add In?

[KS] You can use VB6 or VS.NET for this. I probably would not recommend
using Office XP Developer. In general, for earlier versions of Outlook I
wouldn't expect necessarily that the pre-requisites for a .NET addin would
be installed. That would be the Framework, the PIA's, Extensibility.DLL,
possibly the stdole.dll interop component, and a couple of KB fixes. In
that case, unless you plan to deploy over a network or a CD or DVD, that
means your users will need to download those things. I usually use VB 6
because it doesn't require all that stuff.
2. I have read about using "Office XP Developer", but I cannot get the
software loaded b/c I need a "Windows Component Update" disk, which I do
not
have. Anyone know where to find this?

[KS] Office XP Developer is no longer supported. Most of us never bothered
with it, so your online support will be limited.
3. I have read that you could create the COM Add In using the VB6 "Addin"
project template. I started doing this the other day and was progressing
fine, but after trying to get the "COM Add In" project template (which
comes
with Office XP Developer) installed, I messed something up and now I
don't
see all my Office applications in the "Designer" item within my project.
Now
I only see "Visual Studio" and "Excel". What controls what is displayed
in
this list? I used to have Outlook available to me, and no longer do?

[KS] No idea. I'd probably try to reinstall VS 6 to fix it.
4. Since my COM Add In will be interacting with the original message's
headers, I have found that the only way to access these is through CDO.
When
I try to access them in a Macro, I get a security dialog prompting to
allow
access to the running code. If I create my COM Add In, is there a way to
digitally sign it such that Outlook trusts the code executing within it?

[KS] CDO is not supported for .NET usage. It is also considered not secure
by Outlook so it's limited and fires those security prompts. Code signing
will not help with that, and Outlook 2002 doesn't implicitly trust COM
addins as Outlook 2003 and 2007 do, so your options for the security are
limited. See http://www.outlookcode.com/d/sec.htm for those options. I
personally use Redemption to avoid the security prompts.
I know this is alot and could take up several postings, but any help is
appreciated!!
 
B

Brian McCullough

Ken,

In addition, I just downloaded this sample of an Outlook Add In written for
Office 2000 (not XP!): http://www.microeye.com/resources/itemsCB.htm

When I open the VB6 project, I get a completely different list of items in
my Application dropdown. Now I see the following:

Microsoft Outlook
Microsoft PowerPoint
Microsoft Project
Microsoft Publisher


Any ideas on where the values in the Application listbox in the designer is
coming from????

Thanks once again!!! You seem to be very knowlegeable in this area and I am
very new to creating Add Ins, so this is really appreciated!!!



Ken Slovak - said:
Answers inline.




brianpmccullough said:
Hello,

I need to develop an Office XP COM Add-In that needs to extract the
message
headers from an original email and forward these headers along in another
email to a specified email address. A few questions (I have not
developed an
Office/COM Add In before):

1. I come from a developer background, so I am comfortable working with
most development environments and languages (VB, C#, etc). What tools
are
available for me to use to develop this COM Add In?

[KS] You can use VB6 or VS.NET for this. I probably would not recommend
using Office XP Developer. In general, for earlier versions of Outlook I
wouldn't expect necessarily that the pre-requisites for a .NET addin would
be installed. That would be the Framework, the PIA's, Extensibility.DLL,
possibly the stdole.dll interop component, and a couple of KB fixes. In
that case, unless you plan to deploy over a network or a CD or DVD, that
means your users will need to download those things. I usually use VB 6
because it doesn't require all that stuff.
2. I have read about using "Office XP Developer", but I cannot get the
software loaded b/c I need a "Windows Component Update" disk, which I do
not
have. Anyone know where to find this?

[KS] Office XP Developer is no longer supported. Most of us never bothered
with it, so your online support will be limited.
3. I have read that you could create the COM Add In using the VB6 "Addin"
project template. I started doing this the other day and was progressing
fine, but after trying to get the "COM Add In" project template (which
comes
with Office XP Developer) installed, I messed something up and now I
don't
see all my Office applications in the "Designer" item within my project.
Now
I only see "Visual Studio" and "Excel". What controls what is displayed
in
this list? I used to have Outlook available to me, and no longer do?

[KS] No idea. I'd probably try to reinstall VS 6 to fix it.
4. Since my COM Add In will be interacting with the original message's
headers, I have found that the only way to access these is through CDO.
When
I try to access them in a Macro, I get a security dialog prompting to
allow
access to the running code. If I create my COM Add In, is there a way to
digitally sign it such that Outlook trusts the code executing within it?

[KS] CDO is not supported for .NET usage. It is also considered not secure
by Outlook so it's limited and fires those security prompts. Code signing
will not help with that, and Outlook 2002 doesn't implicitly trust COM
addins as Outlook 2003 and 2007 do, so your options for the security are
limited. See http://www.outlookcode.com/d/sec.htm for those options. I
personally use Redemption to avoid the security prompts.
I know this is alot and could take up several postings, but any help is
appreciated!!
 
K

Ken Slovak - [MVP - Outlook]

Randy's ItemsCB uses an Addin project, which uses a designer. I myself when
I use a designer always remove the VB addin implementation and use an
Implements IDTExtensibility2 implementation. It will work either way but I
prefer that for my Office COM addins.

I have no idea why you aren't seeing the other Office apps listed, obviously
setting up that Office XP Developer did something but I have no idea what. I
used the previous Office 2000 Developer a couple of times for one of my
Outlook programming books, but never had any problems like you're seeing.

The designer is a class module that also does the registration, as you
implied. You can definitely use a standard class module and Implement
IDTExtensibility2 in it, handle all the implementation events and go from
there. A designer is not required.

If you don't use a designer then registration won't be automatic when the
addin is installed or someone runs regsvr32 on the addin DLL. The designer
gives you a self-registering DLL.

You can write out the required registry settings to HKCU or HKLM using an
installer, a reg file or some other method such as a custom action or
script. You would need the following in either HKCU or HKLM:

HKCU\Software\Microsoft\Office\Outlook\Addins\MyConnect.Connect :

MyConnect.Connect is the name. Substitute your addin name and then the name
of the class module you are using that implements IDTExtensibility2. This is
a public class.

Under that key you need the following registry values:

CommandLineSafe REG_DWORD 0
Description REG_SZ description of the
addin
FriendlyName REG_SZ friendly name for the
addin
LoadBehavior REG_DWORD 3 for load on startup

You could also just use the ItemsCB project as a template and go from there.
Many people have done that over the years.
 
B

Brian McCullough

I never got Office Developer installed. I couldn't get passed the first
step, which prompts me for the Windows Component Update CD. All I did was
copy the "COM Add In" project template files from the Office XP Developer
installation CD into the "C:\Program Files\Microsoft Visual
Studio\VB98\Template\Projects" folder on my dev box. It notes to do this in
the following article:

http://msdn2.microsoft.com/en-us/library/aa140195(office.10,d=printer).aspx

Search for the section titled "Before Creating the Sample COM Add-in" in
this article and you will see where it talks about doing this.

Looking back, the COM Add In project template doesn't provide you with a
heck of a lot more to get you going. If anything it appears to complicate
matters. I thought that this template was "needed" to create a COM Add In
for Office, but that doesn't appear to be the case. Lesson 1 learned!! :)

Had I known that you can use just the standard Add In project template
(rather than the "COM Add In" project template), I would have just done this
(like I originally started out doing!).

Well, since the ItemsCB seems to be able to locate Outlook, and that is the
application I need to create my Add In for, I think I will use his as a base
and modify as needed, provided that there are no legal/copyright issues. I
am essentially just going to copy his project, gut it, and just use the
designer which allows me to automatically register this as an Outlook Add
In. All code will be gutted. It doesnt sound like this is an issue since
"Many people have done that over the years."

Once again, thank you for your help!!!

-Brian
 
B

Brian McCullough

I am able to get my Add In working in Outlook now.

One more question for you Ken...

I am using the code at the bottom of this posting to get the Internet
Headers of my message in Outlook (Currently Outlook 2003, but soon will be
Outlook XP). When the code marked with
the 'SECURITY DIALOG HERE!! comment gets executed, I get prompted with a
security dialog that asks me if I want to allow this action. (it reads: "A
program is trying to access e-mail addresses you have stored in Outlook. Do
you want to allow this?").

I get this message with a Macro or with a COM Add In. Is there anyway to
get at the
Internet Headers (either through VBA, VB6, C++, etc) to prevent this message
from being displayed? Is there a way to mark a Macro or Add-In as "safe"
and
prevent the security dialog from appearing?

TIA

Private Function GetMessageHeaders(entryId As String)
Dim objCDO As MAPI.Session
Dim objMsg As MAPI.Message
Dim oFields As MAPI.Fields
Dim strMessageHeader As String

On Error Resume Next

Set objCDO = CreateObject("MAPI.Session")
objCDO.Logon "", "", False, False
Set objMsg = objCDO.GetMessage(entryId)
Set oFields = objMsg.Fields

'SECURITY DIALOG HERE!!
strMessageHeader = oFields.Item(&H7D001E).Value

GetMessageHeaders = strMessageHeader

Set objCDO = Nothing
Set objMsg = Nothing
Set oFields = Nothing
End Function
 
K

Ken Slovak - [MVP - Outlook]

That will work but don't be too quick to gut all the code in the project.

Randy contributed that to the public domain and the code in the project has
workarounds for the problems of OnDisconnection not firing if any Outlook
objects are still instantiated. His Explorer wrapper and wrapper class are
useful for that and for any applications where you need to create a
CommandBars interface.

There is a lot of useful stuff in ItemsCB, written by a noted Outlook
developer MVP and author, who is now the PM in charge of the Outlook object
model on the Outlook team.
 
K

Ken Slovak - [MVP - Outlook]

The Outlook object model doesn't expose the PR_TRANSPORT_MESSAGE_HEADERS
property that has the Internet headers. CDO is considered as unsafe and any
CDO access provokes the security, unless you are on Exchange and an admin
deploys the security form to give permission to CDO code to execute. Macros,
addins or whatever that use CDO to get the headers will provoke the
security.

Extended MAPI won't do that but it can only be used with C++ or Delphi and
has a very long learning curve. You can use the personal version of
Redemption (www.dimastr.com/redemption) for free if you don't intend to
distribute the project. That is immune to the security. I use Redemption
myself for most restricted accesses to Outlook and for things not exposed in
the object model.
 
B

Brian McCullough

Well, I am in consulting and we are to provide the project to a client.
They will use it for internal use only, not for resale. Is that an
acceptable use of Redemption? I like the idea of using it and it should
definitely simplify the development, but I have to make sure the client is
OK with installing this third party application.

What are your thoughts on using something like MAPIProp (see link below), or
perhaps bypassing this all together and making direct calls to the mapi
interface (which looks like MAPIProp and Redemption are just wrappers for
anyway)?

http://www.mapilab.com/articles/vb_outlook_security_1.html

Thanks again!

Brian
 
K

Ken Slovak - [MVP - Outlook]

I use the redistributable version of Redemption myself, but I do many addins
that use it.

I've used MAPIProp using VB6. That has limits though in what you can access
and how. I've used it for PT_STRING8 properties and PT_BOOLEAN and a few
others but it's not always something that will work. That was for clients
that refused to permit a 3rd party library.
 
B

Brian McCullough

I only need it to READ the Internet Headers of an email message. Everything
else that I need to do, such as create a new mail message, specify the To
address and Body, add an attachment (the original email message), Send the
new message, and delete the original message can be done with the Outlook
objects. The only thing not available to me is the Internet Header of the
original message.

Specifically, I am looking to make calls directly to the mapi.dll (which is
what people mean by "Extended MAPI" correct?) as shown in this portion of
the article that I sent earlier:

http://www.mapilab.com/articles/vb_outlook_security_4.html

There aren't any other requirements, and my POC code appears to be able to
access the Internet Headers using an Outlook MailItem object's "hidden"
MAPIOBJECT property just fine (again using code similar to the link above).

From your experience, have you written similar code? If so, have you had
any problems with using it (i.e. memory issues, Outlook crashing, etc)?


Thanks!!!!!

Brian
 
K

Ken Slovak - [MVP - Outlook]

Just make sure you can fall back to an IStream read of the headers if
they're over 8K (store provider dependent). MAPI returns an out of memory
error if you access a large PT_STRING8 using a property that way, you have
to fall back to a stream.

Look at how OutlookSpy does it. It returns the error but if you select the
property it can read it. That's a stream fallback.

You also have to be able to correctly locate and load the MAPI.DLL file and
take into account whether Outlook is the default mail provider, the Outlook
version, the OS, and a couple of other things. It also won't work in debug
mode for some reason.
 
B

Brian McCullough

Ken,

Not sure I am following this...

Are you saying that, for example, different versions and/or implementations
of Exchange (or some other Mail Server application) might store the headers
in a different way? I thought the last portion of the Extended MAPI
property index defined how to return the value. For example, &H7D001E, the
"001E" defines PT_STRING8. Wouldn't that mean that I always got this value
as a string?

Can you provide a link that explains what you are talking about in more
detail?

After getting my POC code working on my machine, this is concerning me
now...

Thanks!

Brian
 
K

Ken Slovak - [MVP - Outlook]

There is no link that I'm aware of. This is all information I figured out
using HrGetOneProp from VB 6 and testing on different versions and modes of
Outlook and different versions of Windows, with different default MAPI
providers.

The name of the MAPI DLL might be different, it's location in the file
system might vary, it may or may not be in a path that doesn't need a full
path specification when using LoadLibrary. If Outlook Express is the default
MAPI provider (or Eudora) then things are different than if Outlook is the
default provider. Store provider might also make a difference (PST versus
Exchange and so on).

The property tag you use to get the headers and the fact that Extended MAPI
returns the data as PT_STRING8 is a constant. How you locate and load the
MAPI DLL differs. It also differs if a user is using Outlook 2000 Internet
only mode than if using a different version or mode.

For normal mode you would call to "msmapi.dll" and for Internet only mode
you have to use "mapi32.dll" as just one example. All I'm saying is it's
only neat and cut and dried if you have control over the user's setup and
always know what it will be. In the wild you have to work with what you have
and take account of all possible variations.
 
B

Brian McCullough

My client is running Windows XP and Outlook XP. I don't believe there are
any variations of this in their environment. I will be sure to specify this
in our statement of work and documentation. I am not planning on
distributing to anyone else.

So, assuming I have a Windows XP and Outlook XP setup on a personal VPC, it
is a pretty good bet that code that is executing on my VPC should work in
their environment as well.

Ken, it is obvious that you have extensive knowledge and expertise in this
area and your time/willingness to help is definitely appreciated!!!

-Brian
 
K

Ken Slovak - [MVP - Outlook]

You can assume that, whether the assumption always proves out as true in the
field is another matter. Only time will tell with that.
 
B

Brian McCullough

Ken,

What is normally used to create an MSI for a VB6 COM Add In (written for
Office XP, specifically for Outlook XP)?

Thanks!
 
B

Brian McCullough

Ken,

I think I made a mistake and did my Windows XP COM Add In development on a
box with Outlook 2003 installed. I assumed that most almost everything would
be the same between the two.

Well, I am recompiling and testing my Add In on my Office XP box. Now when
my application hits the following line I am getting another security prompt:

objNewMessage.Send

This time the prompt reads "A program is trying to automatically send e-mail
on your behalf. Do you want to allow this? If this is unexpected, it may
be a virus and you should choose 'No'."

I assume this is related to the Outlook Security Mechanisms again, and there
are no easy ways of getting around this. The way I see it, the options are:

1. Create the Public Folder Form to disable the security settings. Thus
this and other security dialogs will be disabled, but this would require a
large effort in configuring and also prevents "real" viruses from being
stopped.

2. Use Redemption to send the email.

Are there any other alternatives? I think coding method calls against
Extended MAPI (as I was doing to get the Internet Headers) could be
significantly more complicated for sending an email, and probably not
something that we want to get into.

If we must use Redemption, what is the licensing/pricing for this tool can
can it handle the 'Safe' sending of emails?

TIA!!!

Brian
 
K

Ken Slovak - [MVP - Outlook]

There are lots of ways to create an MSI. There's commercial installation
software such as Wise and InstallShield, there's Orca in Visual Studio, I
think VS6 also had a limited version of InstallShield (maybe only in the
Enterprise version), I think there are free MSI generators but they might
only be for .NET.
 

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