Import Office Interfaces

N

NickP

Hi there,

I am making a C++ shared addin for Microsoft Office and would like to
import the relevant interfaces so that I can interface with the Application
object.

I can import the interfaces for all Office applications, but as it is a
shared add-in, where do I find the base Application object?

TIA.

Nick.
 
N

NickP

So fair in my stdafx.h file I have the following,

#undef ExitWindows
//Office TypeLibraries
#import "C:\Program Files\Common Files\Microsoft Shared\OFFICE12\mso.dll"
named_guids
#import "C:\Program Files\Common Files\Microsoft
Shared\VBA\VBA6\VBE6EXT.OLB" named_guids
using namespace Office;
using namespace VBIDE;
#import "c:\Office12\MSWORD.OLB" named_guids

Unfortunately this results in the following error,

Error 3 fatal error LNK1179: invalid or corrupt file: duplicate COMDAT
'_IID_AddIn' stdafx.obj

Any ideas on where I am going wrong?

I have just read a code project article titled "ATL COM Shared Add Ins Using
C++ The Easy Way" but this suggests *allot* of effort just to expose the
interfaces for the COM objects. Surely this can be done via a simple
imports statement like I am currently doing?

TIA.
 
J

Jialiang Ge [MSFT]

Hello Nick,

From your post, my understanding on this issue is: you want to know how to
resolve the error LNK1179 (invalid or corrupt file: duplicate COMDAT
'_IID_AddIn') and how to access the Application object in the shared
add-in. If I'm off base, please feel free to let me know.

For the first question, error LINK1179 indicates that there are some
duplicate Class of Interface defined in the libraries you #imported. To
resolve the error, you need to rename the namespace of imported libraries.
For instance:

In the project¡¯s stdafx.h, add the following code: (NOTE: the attribute
¡®named_guids¡¯ is removed)
#import "C:\\Program Files\\Microsoft Office\\Office\\mso9.dll"
rename_namespace("Office2000")
using namespace Office2000;
#import "C:\\Program Files\\Common Files\\Microsoft
Shared\\VBA\\VBA6\\VBE6EXT.olb"
rename_namespace("VBE6")
using namespace VBE6;
In the project¡¯s Addin.h file, towards the top, add:
#import "C:\\Program Files\\Microsoft Office\\Office\\MSWORD9.olb"
rename("ExitWindows","MyExitWindows"),named_guids,
rename_namespace("MSWord")
using namespace MSWord;

You may also refer to the code project article:
http://www.codeproject.com/com/adwordaddin.asp, to learn how to use #import
to do automation from VC++.

For the second question about how to access the Application object, you
need to implement the interface: _IDTExtensibility2 in your add-in class.
In the method: OnConnection of _IDTExtensibility2, it has a parameter
IDispatch * Application:
STDMETHOD(OnConnection)(IDispatch * Application, ext_ConnectMode
ConnectMode, IDispatch * AddInInst, SAFEARRAY * * custom) {¡­}
This ¡®Application¡¯ points to the Application object we are in need of.
CComQIPtr <Word::_Application> spApp(Application);

Please let me know if you have any other concerns, or need anything else.

Sincerely,

Jialiang Ge ([email protected], remove ¡®online.¡¯)

Microsoft Online Community Support
==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box ¡°Tools/Options/Read: Get 300 headers at a time¡±
to see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided ¡°AS IS¡± with no warranties, and confers no
rights.
 

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