getting the path of the add-in dll -- error casting addInInst

J

joel

HI

In VS .net c#, I am trying to get the path of the add-in to run the
help file there.

I tried:

public class Connect : Object, Extensibility.IDTExtensibility2
{
public static PowerPoint.Application applicationObject;
public static PowerPoint.AddIn addInObject;

public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
applicationObject = (PowerPoint.Application)application; addInObject =
(PowerPoint.AddIn)addInInst;
MessageBox.Show(addInObject.Path);

But I get the message "Specified cast is not valid", apparently
referring to the line: addInObject = (PowerPoint.AddIn)addInInst;

Any ideas what I am doing wrong? Or is there another way to get the
add-in path?

THanks, Joel
 
J

joel

Hi again,

Ok, I have the answer. The cast is no good cause addInInst is a
COMAddIn object.

C# code:

public class Connect : Object, Extensibility.IDTExtensibility­2
{
public static Microsoft.Office.Core.COMAddIn addInObject;
public void OnConnection(...)

addInObject = (Microsoft.Office.Core.COMAddIn)addInInst;
RegistryKey clsidKey = Registry.ClassesRoot.OpenSubKey(
addInObject.ProgId + "\\CLSID" );
string clsid = (string) clsidKey.GetValue( "" );
RegistryKey com = Registry.ClassesRoot.OpenSubKey( "CLSID\\" + clsid +
"\\InprocServer32" );
AddInDirectory = Path.GetDirectoryName((string) com.GetValue(
"CodeBase" ));

Cheers,

Joel
 

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