COM interfaces and making different overrides for methods


Some Developer

Assume there is a COM server on the system which exposes
an object with the interface below. GetBuffer() will
fill a buffer of several different types... and its a
pain to have to allocate an unmanaged buffer and marshal
each one manually. Isn't there a way to indicate
overrides for methods? I tried just adding the method
definitions and setting a DispId, but the DispId has no
effect with ComImport, and the order of methods confuses
COM/.NET (.NET sees that as three different distinct

The only solution I've found was to redefine the entire
interface and make custom method definitions for each
interface... but the interface is actually *MUCH* larger
than the one below... plus its a pain to have two
different names for each interface override.

Any input would be appreciated.

[ComImport, Guid("9473974-some-guid-124359")]
public interface ITestInterface
void GetBuffer(
[Out] out Guid guid);

void GetBuffer(
[Out] out CustomStructure data);

void GetBuffer(
[In, Out] IntPtr buffer);



Dmitriy Lapshin [C# / .NET MVP]


To the best of my knowledge, overloaded methods are not supported by the COM
specification. What you could do instead is to accept a parameter of type
VARIANT, and treat the passed parameter depending on the VT_TYPE of the
passed argument.

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