There is no spoon
There is no spoon

Reputation: 1796

Delphi Excel COM-Addin

I am writting an MS Excel COM-Addin in Delphi 2006. I'm have Excel 2007 installed on my development machine.

I started the project as an ActiveX Library and then added an Automation object from the Delphi ActiveX project menu.

In my automation object I defined the IDTExtensibility2 interface as

IDTExtensibility2 = interface(IDispatch)
  ['{32E456FC-C710-43AA-9ACA-DDE8F132B91B}']
  function OnAddinsUpdate(var w_Custom: OleVariant): HResult; stdcall;
  function OnBeginShutDown(var w_Custom: OleVariant): HResult; stdcall;
  function OnConnection(const w_Application: IDispatch; w_ConnectMode: Integer;
                      const w_AddInInst: IDispatch; var w_Custom: OleVariant): HResult; stdcall;
  function OnDisconnection(w_DisconnectMode: Integer; var w_Custom: OleVariant): HResult; stdcall;
  function OnStartupComplete(var w_Custom: OleVariant): HResult; stdcall;
end;

and implemented the interface in a class that derived from TAutoObject.

In the initialization section of the unit I call

TAutoObjectFactory.Create(ComServer, TPBSExcelAddin, Class_PBSExcelAddin, ciSingleInstance, tmApartment);

com object registers fine and shows up in Excel Addin options however it will in install in excel. I just get the error "Not loaded. An error has occurred during the loading of the COM Addin"

Can anyone see a problem with my interface? or the way I am creating the com object? is there a way to debug this?

Thank you

Upvotes: 4

Views: 2169

Answers (2)

David Heffernan
David Heffernan

Reputation: 612794

You've got your declaration of IDTExtensibility2 wrong. It should be:

IDTExtensibility2 = interface(IDispatch)
  ['{B65AD801-ABAF-11D0-BB8B-00A0C90F2744}']
  procedure OnConnection(const Application: IDispatch; ConnectMode: ext_ConnectMode;
                         const AddInInst: IDispatch; var custom: PSafeArray); safecall;
  procedure OnDisconnection(RemoveMode: ext_DisconnectMode; var custom: PSafeArray); safecall;
  procedure OnAddInsUpdate(var custom: PSafeArray); safecall;
  procedure OnStartupComplete(var custom: PSafeArray); safecall;
  procedure OnBeginShutdown(var custom: PSafeArray); safecall;
end;

One thing that is crucial to remember is that methods in an interface must be declared in the correct order—you declared them in the wrong order. I also don't know where you got your GUID from.

I obtained this interface declaration by importing the type library for Microsoft Add-In Designer. I strongly recommend that you do the same.

Upvotes: 4

The_Fox
The_Fox

Reputation: 7062

Yes, there is a way to debug this:

  1. Close Excel
  2. Open your project options (Ctrl+Shift+F11)
  3. Go to the Linker tab
  4. Check Include TD32 debug info and Include remote debugging symbols. (Maybe only the first is needed, but better safe than sorry)
  5. Go to Run Parameters (Run menu, Parameters...)
  6. Change the Host Application to Excel
  7. Rebuild and run, as soon as your addin is loaded you can start debugging.

When you never get into debugging, which means the problem is probably not in your initialization code, then maybe there is a problem with loading the necessary packages or, your addin does not implement the _IDExtensibility interface the right way.

Upvotes: 1

Related Questions