How call virtual function in COM in C#
See the question and my original answer on StackOverflowThis would be a C# equivalent (you don't need to define IUnknown methods, and this
is implicit):
[Guid("F885120E-3789-4FD9-865E-DC9B4A6412D2"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IARPUninstallStringLauncher
{
[PreserveSig]
int LaunchUninstallStringAndWait(
IntPtr hKey,
[MarshalAs(UnmanagedType.LPWStr)] string Item,
bool bModify,
IntPtr hWnd);
[PreserveSig]
int RemoveBrokenItemFromInstalledProgramsList(
IntPtr hKey,
[MarshalAs(UnmanagedType.LPWStr)] string Item);
}
You can declare the coclass like this (yes, with an empty body)
[Guid("FCC74B77-EC3E-4DD8-A80B-008A702075A9"), ComImport]
public class UninstallStringLauncher
{
}
And to create and use the object, you can try a code like this
var launcher = (IARPUninstallStringLauncher)new UninstallStringLauncher();
And make sure the bitness (x86/x64) of your COM object matches the bitness of your C# app.