What happened to my general add-in constructor?

Good morning, fellows developers:

I am currently trying to fix several performance issues for the Excel extended add-in inherited from a previous developer, basically I am trying to find how the add-in works inside Excel, that is, I was looking for a network for information, I understand:

  • The value of 3 must be set in the LoadBehavi registry
  • An Excel workbook must preload all add-ins specified in a VBA project during an open event
  • After opening the document, my add-in should be available for use with VBA code.

Now I am adding Log4Net to the add-in and, oddly enough, I saw the following behavior

There is a global variable in an Excel workbook during an open event

Public myAddin As Object

Set myAddin = New TradingAddin.TradingAddin

Thus, the C # class Contractor is called.

, IDTExtensibility2 OnConnection, OnDisconnection .. , .

, Excel , VBE, -

Set myAddin = Application.COMAddins.Item("Trading").Object

Nothing , #, Excel.

:

- Visual Studio 2005 Team Edition, - Excel 2003, - . VSTO.

, VBA,

Set addIn = Application.COMAddIns.Item("K2Trading.K2Trading").Connect

Set managedObject3 = addIn.Object <--- This value that I thought was an Instance of the Add-in is equal to Nothing (NULL)

Set addIn = Application.COMAddIns("K2Trading.K2Trading").Connect

, LoadBehaviour 3 2, , OnConnection Extensibility, OnDisconecction Object Class Constructor, VBA , , VBA , COM-????

ProcMon, Excel ( ) http://blogs.msdn.com/dvespa/archive/2008/10/15/troubleshooting-outlook-com-addins-using-procmon.aspx.

, , , ?

, COM- ? , , COM-?

,  

:

, Unspecified error ( HRESULT: 0x80004005 (E_FAIL))

public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode,
    object addInInst, ref System.Array custom)
{
    object missing = System.Reflection.Missing.Value;

    try
    {
        if (debug)
        {
            log.Debug("Connection Mode :" + connectMode);
        }

        this.excelApp = (Excel.Application)application;
        this.addInInstance = addInInst;

        Office.COMAddIn addIn = this.excelApp.COMAddIns.Item(ref addInInst);

        //addIn.Object = this;

        // We connect our Instance of the Add-in to the Arrya of COMAddins of Excel
        VBA.Interaction.CallByName(addIn, "Object", VBA.CallType.Let, this);

        ^
        |
        The Exception occurs here.

, ,

public void OnConnection(
    object application,
    Extensibility.ext_ConnectMode connectMode,
    object addInInst,
    ref System.Array custom)
{
    // Direct call fails b/c ".Object" is a late-bound call:
    //
    //    addInInst.Object = this;


    // Reflection fails I believe b/c .Object is a 'let' assigned
    // property for reference type, which is very unusual even for
    // COM (although legal) and is a foreign concept to .NET. Use
    // of the right BindingFlags here *might* work, but I'm not sure:
    //
    //    PropertyInfo propInfo;
    //    propInfo = addInInst.GetType().GetProperty("Object");
    //    propInfo.SetValue(addInInst, this, null);


    // This works!:
    VBA.Interaction.CallByName(addInInst, "Object", VBA.CallType.Let, this);
}

addInInst Office.COMAddin, , Object ,

, Excel , , , Excel, OnConnection , = AvgCost ( )

?

+3
1

, COM- ? COM-?

COM- ? COM, Excel .

VBA , , VBA COM-????

VBA , DLL, VB6 DLL .NET. , VBA . Excel.Appliction.Run("NameOfYourVbaMacro") , . ( , Excel.Application.Workbooks["NameOfYourAddin.xla"]. , , .) , , ThisWorkbook Worksheet.

, Excel VBE, -

myAddin = Application.COMAddins.Item( "" ).

, , VBA COM COM ( ), , VBA #, COM ? , , , , ... .

COM COM- ComAddin.Object , #, . . :

.

, ...

Mike

:

,

, - ...

, !

, :

VBA.Interaction.CallByName(addIn, "Object", VBA.CallType.Let, this);

"addInInst":

VBA.Interaction.CallByName(addInInst, "Object", VBA.CallType.Let, this);

, :

Office.COMAddIn addIn = this.excelApp.COMAddIns.Item(ref addInInst);

, . , . , , progId COM, , , COM .Object. , .

addInInst Office.COMAddin, , ,

, . , , , IDTExtensibility2. , , , COM, . , , IDTExtensibility2 OnConnection. , 'this'.

, , , . , . , . , , , , .

, ,

Mike

+2

Source: https://habr.com/ru/post/1714369/


All Articles