I am trying to understand what is right, why use COM interfaces from C # code. It is simple when the interface is not inherited from another base interface. Like this:
[ComImport, Guid("2047E320-F2A9-11CE-AE65-08002B2E1262"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IShellFolderViewCB
{
long MessageSFVCB(uint uMsg, int wParam, int lParam);
}
However, everything becomes familiar when I need to implement an interface that inherits from other COM interfaces. For example, if I implement an interface IPersistFolder2that inherits from IPersistFolder, which inherits from IPersist, as I usually do in C # code:
[ComImport, Guid("0000010c-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IPersist
{
void GetClassID([Out] out Guid classID);
}
[ComImport, Guid("000214EA-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IPersistFolder : IPersist
{
void Initialize([In] IntPtr pidl);
}
[ComImport, Guid("1AC3D9F0-175C-11d1-95BE-00609797EA4F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IPersistFolder2 : IPersistFolder
{
void GetCurFolder([Out] out IntPtr ppidl);
}
The operating system cannot call implementation methods of my object. When I debug, I see that the constructor of my implementation IPersistFolder2is called many times, however the interface methods that I implemented are not called. I implement IPersistFolder2as follows:
[Guid("A4603CDB-EC86-4E40-80FE-25D5F5FA467D")]
public class PersistFolder: IPersistFolder2
{
void IPersistFolder2.GetClassID(ref Guid classID) { ... }
void IPersistFolder2.Initialize(IntPtr pidl) { ... }
void IPersistFolder2.GetCurFolder(out IntPtr ppidl) { ... }
}
, COM- , :
[ComImport, Guid("0000010c-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IPersist
{
void GetClassID([Out] out Guid classID);
}
[ComImport, Guid("000214EA-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IPersistFolder : IPersist
{
new void GetClassID([Out] out Guid classID);
void Initialize([In] IntPtr pidl);
}
[ComImport, Guid("1AC3D9F0-175C-11d1-95BE-00609797EA4F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IPersistFolder2 : IPersistFolder
{
new void GetClassID([Out] out Guid classID);
new void Initialize([In] IntPtr pidl);
void GetCurFolder([Out] out IntPtr ppidl);
}
, , COM- ( new). , , IUnknown. - , COM- #, COM- ?