IDispatch implementation

D

Dmitry Medvedev

Hello,

I need to write C# class, that would implement IDispatch interface to be
used in ActiveScript.
I can't use IReflect interface here due to design issues, I need to handle
GetIDsOfNames and Invoke manually.

I've tried the following code:

[Guid("00020400-0000-0000-C000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IDispatch
{
[PreserveSig]
int GetTypeInfoCount(out int Count);
[PreserveSig]
int GetTypeInfo( [MarshalAs(UnmanagedType.U4)] int iTInfo,
[MarshalAs(UnmanagedType.U4)] int lcid, out UCOMITypeInfo typeInfo);
[PreserveSig]
int GetIDsOfNames( ref Guid riid,
[MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPWStr)]
string[] rgsNames,
int cNames, int lcid, [MarshalAs(UnmanagedType.LPArray)] int[]
rgDispId);
[PreserveSig]
int Invoke(int dispIdMember, ref Guid riid, uint lcid, ushort wFlags,
ref DISPPARAMS pDispParams, out object pVarResult, ref EXCEPINFO
pExcepInfo, IntPtr[] pArgErr);


[ClassInterface(ClassInterfaceType.None)]
public class ActiveScriptWrapper : IDispatch
.....

and
Marshal.GetIDispatchForObject(new ActiveScriptWrapper()) results in
exception.

Looks like it's not possible to implement IUnknown and IDispatch interfaces
in .NET classes.

Could anyone help me with this task?

Regards,
Dmitry
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hello!

Do you really need your own IDispatch implementation?
If you just need to make your class accessible to ActiveScript code, just
declare it this way:

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class MyClass
{
}

Could you probably elaborate on what you are going to achieve? Probably this
can be done in other way?
 

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