all groups > dotnet interop > september 2006 >
You're in the

dotnet interop

group:

disp interface


disp interface Roy
9/27/2006 6:52:01 AM
dotnet interop:
I want to rewrite a legacy MFC COM code in C# and DO NOT want to modify and
compile any client code who uses the component at this time. Here is part of
the interface definition. The idl also expose some enum definitions. Any idea
if it can be do easily and how? Some of the interface do not return HRESULT.

[ uuid(...) ]
dispinterface IMyInterface
{
properties:
// NOTE - ClassWizard will maintain property information here.
// Use extreme caution when editing this section.
//{{AFX_ODL_PROP(MyInterface)
//}}AFX_ODL_PROP

methods:
// NOTE - ClassWizard will maintain method information here.
// Use extreme caution when editing this section.
//{{AFX_ODL_METHOD(MyInterface)
[id(1)] SCODE MyFunc1(VARIANT v1, VARIANT* v2);
[id(2)] boolean MyFunc2(float* v1, float* v2);
[id(3)] short MyFunc3(...);
};
Re: disp interface Dmytro Lapshyn [MVP]
10/3/2006 5:44:19 PM
Hi,

Declare an equal interface in .NET code and adorn it with
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)].
Use [DispId] on the interface members to match the original DispIDs. You
might also need to use the [PreserveSig] attribute on the interface members
since there are methods that do not return HRESULT.

Then create a class implementing the interface and adorn it with
[ComVisible(true), ClassInterface(ClassInterfaceType.None)].

Finally, build the assembly and register it for COM interop.

--
Regards,
Dmytro Lapshyn [MVP]
http://blogs.vbcity.com/DmytroL

[quoted text, click to view]
AddThis Social Bookmark Button