Convert IDL to C# RRS feed

  • Question

  • User-1856965531 posted
    Hi, Does anyone know if there is a tool to convert IDL to C#? I would be a useful timesaver. Could anyone confirm the following is correct? IDL [id(2), helpstring("method GetDescription")] HRESULT GetDescription([out] BSTR *descr); C# [DispId(2)] [return: MarshalAs(UnmanagedType.BStr)] string GetDescription(); Thanks!
    Friday, July 2, 2004 7:23 AM

All replies

  • User-1856965531 posted
    Hi, I'm pretty stuck with this now. I need to add new functionality to an existing software tool written in C++. The original designers of the software provided for extension of the tool via In Process Servers, which implement a pre-defined interface (IDL below). As far as I can see, I need to translate the IDL to an interface in C#, and then implement the interface in a class which can be used by the existing software (COM client) via Interop. Not having done this before, I'd appreciate any guidance. Here is what I have so far: IDL to be translated: import "oaidl.idl"; import "ocidl.idl"; [ object, uuid(DCDC3289-96BB-4227-AF40-74BEC457B2AF), dual, helpstring("IEVOPlugIn Interface"), pointer_default(unique) ] interface IEVOPlugIn : IDispatch { [id(1), helpstring("method GetIdName")] HRESULT GetIdName( [out] BSTR *name); [id(2), helpstring("method GetDescription")] HRESULT GetDescription( [out] BSTR *descr); [id(3), helpstring("method GetCmdName")] HRESULT GetCmdName( [out] BSTR *name); [id(4), helpstring("method GetCmdGroupId")] HRESULT GetCmdGroupId( [out] long *id); [id(5), helpstring("method Edit")] HRESULT Edit( [out] long *pHwnd, [in] BSTR stream, [in] int * arrayTipType); [id(6), helpstring("method Read")] HRESULT Read( [out] BSTR *stream); [id(7), helpstring("method NeedLiquidClasses")] HRESULT NeedLiquidClasses( [out,retval] BOOL *need); [id(8), helpstring("method WriteLiquidClasses")] HRESULT WriteLiquidClasses( [in] BSTR stream); [id(9), helpstring("method NeedWastes")] HRESULT NeedWastes( [out,retval] BOOL *need); [id(10), helpstring("method WriteWastes")] HRESULT WriteWastes( [in] BSTR stream); [id(11), helpstring("method NeedCleaners")] HRESULT NeedCleaners( [out,retval] BOOL *need); [id(12), helpstring("method WriteCleaners")] HRESULT WriteCleaners( [in] BSTR stream); [id(13), helpstring("method GetIcon")] HRESULT GetIcon( [out] long *hIcon, [in] BOOL bBig); [id(14), helpstring("method GetInfo")] HRESULT GetInfo( [out] BSTR *name); [id(15), helpstring("method MoveLabware")] HRESULT MoveLabware( [in, out] BSTR *name, [in] int srcGrid, [in] int srcSite, [in] int dstGrid, [in] int dstSite ); }; [ uuid(22FFC10A-F745-4D1D-91E3-5B256E1FE79B), version(1.0), helpstring("evoPlugInConPt 1.0 Type Library") ] library EVOPLUGINCONPTLib { importlib("stdole32.tlb"); importlib("stdole2.tlb"); [ uuid(9C80CD09-56CF-46B9-9231-2AA0F6713E65), helpstring("_IPlugInWizEvents Interface") ] dispinterface _IPlugInWizEvents { properties: methods: [id(1), helpstring("method CallbackInfo")] HRESULT CallbackInfo([in] long id1, [in] long id2, [out] BSTR* bstr); }; }; My C# version so far: using System; using System.Runtime.InteropServices; // required for COM Interop namespace EVOwareWizard { /// <summary> /// Summary description for IEVOPlugIn. /// </summary> // Provide Interface ID as provided in .idl file [Guid("DCDC3289-96BB-4227-AF40-74BEC457B2AF"), // Tell Interop Marshalling Layer how to interpret v-table of interface. // In the .idl file the 'dual' attribute is specified, // meaning that the interface must be compatible with Automation // and be derived from IDispatch (early & late binding). InterfaceType(ComInterfaceType.InterfaceIsDual)] public interface IEVOPlugIn { // convert interface definition from .idl file // [id(1), helpstring("method GetIdName")] HRESULT GetIdName([out] BSTR *name); [DispId(1)] void GetIdName( [Out, MarshalAs(UnmanagedType.BStr)] string name); // [id(2), helpstring("method GetDescription")] HRESULT GetDescription([out] BSTR *descr); [DispId(2)] void GetDescription( [Out, MarshalAs(UnmanagedType.BStr)] string descr); // [id(3), helpstring("method GetCmdName")] HRESULT GetCmdName([out] BSTR *name); [DispId(3)] void GetCmdName( [Out, MarshalAs(UnmanagedType.BStr)] string name); // [id(4), helpstring("method GetCmdGroupId")] HRESULT GetCmdGroupId([out] long *id); [DispId(4)] void GetCmdGroupId( [Out()] int id); // [id(5), helpstring("method Edit")] HRESULT Edit([out] long *pHwnd, [in] BSTR stream, [in] int * arrayTipType); [DispId(5)] void Edit( [Out()] int pHwnd, [In(),MarshalAs(UnmanagedType.BStr)] string stream, [In()] int arrayTipType); // [id(6), helpstring("method Read")] HRESULT Read([out] BSTR *stream); [DispId(6)] void Read( [Out, MarshalAs(UnmanagedType.BStr)] string stream); // [id(7), helpstring("method NeedLiquidClasses")] HRESULT NeedLiquidClasses([out,retval] BOOL *need); [DispId(7)] [return: MarshalAs(UnmanagedType.Bool)] bool NeedLiquidClasses(); // [id(8), helpstring("method WriteLiquidClasses")] HRESULT WriteLiquidClasses([in] BSTR stream); [DispId(8)] void WriteLiquidClasses( [In(), MarshalAs(UnmanagedType.BStr)] string stream); // [id(9), helpstring("method NeedWastes")] HRESULT NeedWastes([out,retval] BOOL *need); [DispId(9)] [return: MarshalAs(UnmanagedType.Bool)] bool NeedWastes(); // [id(10), helpstring("method WriteWastes")] HRESULT WriteWastes([in] BSTR stream); [DispId(10)] void WriteWastes( [In(), MarshalAs(UnmanagedType.BStr)] string stream); // [id(11), helpstring("method NeedCleaners")] HRESULT NeedCleaners([out,retval] BOOL *need); [DispId(11)] [return: MarshalAs(UnmanagedType.Bool)] bool NeedCleaners(); // [id(12), helpstring("method WriteCleaners")] HRESULT WriteCleaners([in] BSTR stream); [DispId(12)] void WriteCleaners( [In(), MarshalAs(UnmanagedType.BStr)] string stream); // [id(13), helpstring("method GetIcon")] HRESULT GetIcon([out] long *hIcon, [in] BOOL bBig); [DispId(13)] void GetIcon( [Out()] int hIcon, [In(), MarshalAs(UnmanagedType.Bool)] bool bBig); // [id(14), helpstring("method GetInfo")] HRESULT GetInfo([out] BSTR *name); [DispId(14)] void GetInfo( [Out(), MarshalAs(UnmanagedType.BStr)] string name); // [id(15), helpstring("method MoveLabware")] HRESULT MoveLabware([in, out] BSTR *name, [in] int srcGrid, [in] int srcSite, [in] int dstGrid, [in] int dstSite ); [DispId(15)] void MoveLabware( [In(), MarshalAs(UnmanagedType.BStr)] [Out()] string name, [In()] int srcGrid, [In()] int srcSite, [In()] int dstGrid, [In()] int dstSite); } } Many thanks! A.
    Monday, July 5, 2004 11:18 AM
  • User-914773166 posted

    I also have this same problem. can you soleved this?? 

    Please help me to know how to use *.idl file in c#.

    Friday, March 29, 2013 12:14 PM