The dotPeek disassembles Interop DLLs incorrectly

The scenario is disassembling a interop DLL produced by .Net v4.0 (VS2010) tlbimp from TLB generated based on IDL.

The IDL:

       interface ITargetX : IUnknown
   {
      HRESULT Create([in] LPPROGRAMCONTROLLER pProgramController, [in] LPPROGRAMAGENT pProgramAgent);
      HRESULT Run([in, unique] BSTR bstrTargetRunInput, [out] BSTR* bstrTargetRunOutput);
      HRESULT RunInTrain([in, unique] BSTR bstrTargetRunInput, [out] BSTR* bstrTargetRunOutput);
   };



   cpp_quote("////////////////////////////////////////////////////////////////////////////////////////")
   cpp_quote("// Target DUMMY  ")
   cpp_quote("")
   cpp_quote("// CLSID definition for OLE_CREATE macro")
   cpp_quote("#define CLSID_OC_TargetDummy {0xAAAAAAA, 0xAAAA, 0xAAAA, {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}}")
   cpp_quote("////////////////////////////////////////////////////////////////////////////////////////")
   [
      uuid(AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA),
      helpstring("TargetDummy Class")
   ]
   coclass TargetDummy
   {
      [default] interface ITargetX;
   };


The code generated from interop DLL by dotPeek:

  [Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")]
  [TypeLibType(TypeLibTypeFlags.FCanCreate)]
  [ClassInterface(ClassInterfaceType.None)]
  [ComImport]
  public class TargetDummyClass : ITargetRun, TargetDummy
  {
    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
    public TargetDummyClass();

    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
    public virtual void Create([ComAliasName("Mynamespace"), MarshalAs(UnmanagedType.Interface), In] IProgramController pProgramController, [ComAliasName("Mynamespace"), MarshalAs(UnmanagedType.Interface), In] IProgramAgent pProgramAgent);

    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
    public virtual void Run([MarshalAs(UnmanagedType.BStr), In] string bstrTargetRunInput, [MarshalAs(UnmanagedType.BStr)] out string bstrTargetRunOutput);

    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
    public virtual void RunInTrain([MarshalAs(UnmanagedType.BStr), In] string bstrTargetRunInput, [MarshalAs(UnmanagedType.BStr)] out string bstrTargetRunOutput);
  }

This obviously does not compile.

However, same interop disassembled by .NetReflector 8 looks and compiles OK:

[ComImport, Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"), CoClass(typeof(TargetDummyClass))]
public interface TargetDummy : ITargetX
{
}


As you can see a lot of unneeded code added, also the flags looks really wrong .

0

Please sign in to leave a comment.