VC++ COM interface in a DLL : ------------------------------- interface IModuleConfig { HRESULT SetValue( }; DLL component Id is DLL component implements this interface... C# code : I created the instance for the DLL component as follows : [ { } This is like defining the CLSID in VC++... How to create an instance for the specified Guid ? Type t = typeof(DLLComponent); DLLComponent dllComponent; dllComponent = Activator.CreateInstance(t); How to Query the interface from the DLL component Instance ? IModuleConfig config = null; config = dllComponent as IModuleConfig; or config = (IModuleConfig) dllComponent; But we have to declare the IModuleConfig interface in the C# as follows ; [ { } Afterwards we can call the interface method using its object with dot operator... IModuleConfig config = null; config = dllComponent as IModuleConfig; config.SetValue(guid, ref obj); Now it is working well. Wrong code: ============== Previously I defined the C# interface as follows : [ { } I got the exception as follows, we can't use the "UnmanagedType I thank verymuch to muthu pandi anna for helping me to solve this problem. |
Tuesday, August 21, 2007
COM interface and .NET interoperability
Subscribe to:
Post Comments (Atom)
2 comments:
Hi Sundar,
I've been trying to get the IModuleConfig interface working in C# for the past week! I just stumbled across your blog post and it looks like you have it working? I'm trying to use this interface in C# to set parameters on some DirectShow filters.
I would be truly greatful if you could send me your complete C# IModuleConfig code? (stephen DOT larkin AT gmail DOT com)
Kind Regards,
Steve
Hello Sundar,
i already wrote you on elecard forum.
I would be also greatful if you could help me get IModuleConfig working in c# ad i always have a E_NOINTERFACE error when applyed on IBaseFilter.
(my email is freddyk AT ifrance DOT com)
Thanks in Advance
Freddy
Post a Comment