Faseeh Haris

Faseeh Haris

  • NA
  • 150
  • 3.3k

C# Replace ComImport with standard referenced interface

Oct 2 2019 2:43 PM
  1. using System.Runtime.CompilerServices;  
  2. using System.Runtime.InteropServices;  
  3.   
  4. namespace MyProject.Developer  
  5. {  
  6. [ComImport]  
  7. [TypeLibType(4160)]  
  8. [Guid("AAEDE8D0-E600-11D1-97E8-006008103DE4")]  
  9. public interface IPDTool  
  10. {  
  11.     [MethodImpl(MethodImplOptions.InternalCall)]  
  12.     [DispId(1)]  
  13.     void CheckTool([In] int lFeature, out int plVersion, out int plType);  
  14.   
  15.     [MethodImpl(MethodImplOptions.InternalCall)]  
  16.     [DispId(2)]  
  17.     bool GetConfigBool([In] [MarshalAs(UnmanagedType.BStr)] string                bstrKey, [In] bool bDefault);  
  18.   
  19.     [MethodImpl(MethodImplOptions.InternalCall)]  
  20.     [DispId(3)]  
  21.     int GetConfigLong([In] [MarshalAs(UnmanagedType.BStr)] string bstrKey, [In] int lDefault);  
  22.   
  23.     [MethodImpl(MethodImplOptions.InternalCall)]  
  24.     [DispId(4)]  
  25.     [return: MarshalAs(UnmanagedType.BStr)]  
  26.     string GetConfigString([In] [MarshalAs(UnmanagedType.BStr)] string   bstrKey, [In] [MarshalAs(UnmanagedType.BStr)] string bstrDefault);  
  27.    }  
  28. }  
  29.   
  30.   
  31.   
  32. using System.Runtime.InteropServices;  
  33.   
  34. namespace MyProject.Developer  
  35. {  
  36. [ComImport]  
  37. [CoClass(typeof(MyNETToolClass))]  
  38. [Guid("AAEDE8D0-E600-11D1-97E8-006008103DE4")]  
  39. public interface MyNETTool : IPDTool  
  40. {  
  41. }  
  42. }  
  43.   
  44.   
  45.   
  46. using System;  
  47. using System.Runtime.CompilerServices;  
  48. using System.Runtime.InteropServices;  
  49.   
  50. namespace MyProject.Developer  
  51. {  
  52. [ClassInterface((short)0)]  
  53. [Guid("11429564-E600-4903-82A5-D45AB82B860B")]  
  54. [TypeLibType(2)]  
  55. public class MyNETToolClass : MyNETTool, IPDTool  
  56. {  
  57.     [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]  
  58.     public extern MyNETToolClass();  
  59.   
  60.     [DispId(1)]  
  61.     [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]  
  62.     public virtual extern void CheckTool([In] int lFeature, out int plVersion, out int plType);  
  63.   
  64.     [DispId(2)]  
  65.     [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]  
  66.     public virtual extern bool GetConfigBool([In] string bstrKey, [In] bool bDefault);  
  67.   
  68.     [DispId(3)]  
  69.     [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]  
  70.     public virtual extern int GetConfigLong([In] string bstrKey, [In] int lDefault);  
  71.   
  72.     [DispId(4)]  
  73.     [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]  
  74.     public virtual extern string GetConfigString([In] string bstrKey, [In] string bstrDefault);  
  75.     }  
  76. }  

I have some assemblies in a solution one of which uses a ComImport. I would like to eliminate the ComImport as all the projects are in the same solution and simply reference but I keep getting errors that relate to the ComImport. Mainly when I reference the .dll it still thinks it is not referenced. How can I convert this to a standard interface that I can reference?