COM interfaces and making different overrides for methods


S

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
methods).

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")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ITestInterface
{
[DispId(1)]
void GetBuffer(
[Out] out Guid guid);

[DispId(1)]
void GetBuffer(
[Out] out CustomStructure data);

[DispId(1)]
void GetBuffer(
[In, Out] IntPtr buffer);
}
 
Ad

Advertisements

D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

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

Top