Overloaded Methods

A managed class can have overloaded methods. A single method name can have multiple argument lists and return values. Unfortunately, COM does not support overloaded methods. The CCW that .NET exposes to unmanaged clients handles this mismatch by exposing one unmanaged method that has the exact name as the overloaded method. It then exposes the other overloaded versions of the method with _N appended to the managed name where N starts at 2. For instance, given the following managed class, which has three different versions of a method called TestMethod:

using System;
using System.Runtime.InteropServices;
namespace TestOverload
{
    public class TestClass
    {
      public TestClass()
      {

      }
      public string TestMethod(int arg1)
					{
					return "TestMethod(int ...

Get .NET and COM Interoperability Handbook, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.