C#COM组装实现C 接口
C# COM assembly implementing C++ interface
是否有人知道C#中C 接口的以下实现是否正确,尤其是关于GUID类型的编组。
我们正在实施的原始C :
[
object,
pointer_default(unique),
uuid(Z703B6E9-A050-4C3C-A050-6A5F4EE32767)
]
interface IThing: IUnknown
{
[propget] HRESULT Prop1([out, retval] GUID* prop1);
[propget] HRESULT Prop2([out, retval] EnumProp2* prop2);
[propget] HRESULT Prop3([out, retval] HSTRING* prop3);
};
我们的C#com组装中的转换接口:
[ComVisible(true), Guid("Z703B6E9-A050-4C3C-A050-6A5F4EE32767"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IThing
{
Guid Prop1 { get; }
EnumProp2 Prop2 { get; }
string Prop3 { get; }
}
具体类:
public class Thing : IThing
{
public Thing(Guid prop1, EnumProp2 prop2, string prop3)
{
Prop1 = prop1;
Prop2 = prop2;
Prop3 = prop3;
}
public Guid Prop1 { get; }
public EnumProp2 Prop2 { get; }
public string Prop3 { get; }
}
事实证明,问题实际上不是对Guid
结构进行编写,而是string
。
看来,当将字符串从托管的CLR堆移动到不受管理的堆时,默认的填充类型为unmanagedtype.bstr.bstr(Unicode字符串,长度置换) - 在这种情况下,主机应用程序需要不同的元帅类型:
public string Name { [return: MarshalAs(UnmanagedType.HString)]get; }
相关文章:
- 如何从实现接口的模板化类实例访问结构
- 传递实现特定接口的类
- 如何在C++中实现接口
- C++ 使用接口和默认实现继承
- unique_ptr实现接口时对已删除函数的引用
- C++接口实现和子类化对象识别
- 接口实现和私有继承之间的交互
- Pimpl习惯用法、单独的接口/实现文件和多个虚拟继承.如何
- 定义大量的接口实现
- cpp文件中的纯虚拟接口实现
- 如何使用接口实现回调
- 继承接口实现
- 如何在C++中编写类java参数级接口实现
- 具有其他默认参数的接口实现
- Mixin和接口实现
- 如何在许多类中重用接口实现
- Emscripten Javascript接口实现
- 获取Firefox内置组件的接口实现
- c++中的头文件和Java中的抽象类/接口实现是相同的想法,这是正确的吗?
- C++中的接口+实现:代码不执行