By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,677 Members | 1,177 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,677 IT Pros & Developers. It's quick & easy.

IDispatch implementation

P: n/a
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

Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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?

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Dmitry Medvedev" <d_****@svitonline.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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


Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.