Ich versuche, ein COM-Objekt daraus zu exportieren. Ich habe Folgendes:
Code: Select all
[Guid("....")]
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IMyService
{
void DoWork();
}
[ComVisible(true)]
[Guid("...AnotherGuid...")]
[ClassInterface(ClassInterfaceType.None)]
public class MyService : IMyService
{
void DoWork() { }
}
...
RegistrationServices regServices = new RegistrationServices();
int result = regServices.RegisterTypeForComClients(
typeof(MyService),
RegistrationClassContext.LocalServer,
RegistrationConnectionType.MultipleUse);
...
Code: Select all
GUID classGuid = { ... guid of MyService ... };
GUID ifaceGuid = { ... guid of IMyService ... };
IUnknown* p;
// This returns E_NOINTERFACE !
auto hr = CoCreateInstance(classGuid, CLSCTX_ALL, NULL, ifaceGuid, (LPVOID*)&p);
Ich habe sogar ein TLB aus .net exportiert und es erfolgreich mit #import auf der CPP-Seite importiert und den Smart Pointer verwendet ... aber dort ist es dasselbe - CoCreateInstance mit IID_IUnknown funktioniert und dann gibt QueryInterface E_NOINTERFACE zurück.
Ich bin sogar noch weiter gegangen und habe IMyService von ICustomQueryInterface geerbt und implementiert GetInterface wie folgt:
Code: Select all
public CustomQueryInterfaceResult GetInterface(ref Guid iid, out IntPtr ppv)
{
if (iid == typeof(IMyService).GUID)
{
ppv = Marshal.GetComInterfaceForObject(this, typeof(MyService), CustomQueryInterfaceMode.Ignore);
return CustomQueryInterfaceResult.Handled;
}
ppv = IntPtr.Zero;
return CustomQueryInterfaceResult.NotHandled;
}
Ich bin ratlos.
Hilfe?
