Determining .Net method suffix number in VBScript (COM-interop)

后端 未结 2 1642
长情又很酷
长情又很酷 2020-12-07 03:37

You can use .NET methods through COM-interop in VBScript. You have to append a certain suffix number to the method since overloads don\'t cross the managed/unmanaged boundar

相关标签:
2条回答
  • 2020-12-07 03:51

    Microsoft document Exported Member Conversion -- Overloaded Methods already explain all. In brief, @Nilpo 's answer is right, quickest way is usually just trial and error.

    Overloaded Methods

    Although .NET supports overloaded methods, the IDispatch interface relies solely on method name for binding, rather than the complete method signature. It is therefore not capable of supporting overloaded methods. However, to provide access to overloaded methods of a type, Tlbexp.exe decorates the names of overloaded methods with an ordinal number so that each method name is unique.

    The following managed and unmanaged signatures show the inclusion of numbers:

    Managed signature

    interface INew { public:
        void DoSomething();
        void DoSomething(short s);
        void DoSomething(short l);
        void DoSomething(float f);
        void DoSomething(double d);
    }
    

    Unmanaged signature

     interface INew {
        void DoSomething();
        void DoSomething_2(short s);
        void DoSomething_3(short l);
        void DoSomething_4(float f);
        void DoSomething_5(double d);
    }
    

    The COM signature for the methods appears as a single DoSomething method followed by a series of decorated DoSomething_x methods, where x starts at 2 and increments for each overloaded form of the method. Note that some of the overloaded methods can be inherited from a base type. However, there is no guarantee that overloaded methods will retain the same number as the type version advances.

    Although .NET clients can use the overloaded form of the method, COM clients have to access the decorated methods. Object browsers display all forms of the decorated method with the method signature to enable you to select the correct method. The late-bound client can also call IDispatch::GetIdsOfNames, passing in the decorated name to get the DispID of any overloaded method.

    0 讨论(0)
  • 2020-12-07 03:54

    Since VBScript does not have support for overloaded methods, each overloaded method in a class is named uniquely using numbers appended to their name. They are numbered in the order in which they are defined in the original class. More information in my article Using .Net Interops in VBScript on ASP Free.

    0 讨论(0)
提交回复
热议问题