[英]How do I access IMetaDataEmit and other MetaData COM interfaces from C# or F#?
I am writing a compiler in F# and I want to be able to access the unmanaged metadata COM interfaces in the .net runtime.我正在用 F# 编写编译器,我希望能够访问 .net 运行时中的非托管元数据 COM 接口。 Before anybody mentions it, Reflection.Emit is not suitable for my purposes , nor do I want to use any other method than the metadata COM interfaces.
在任何人提到它之前, Reflection.Emit 不适合我的目的,我也不想使用元数据 COM 接口以外的任何其他方法。
I've imported mscoree.tlb but it doesn't seem to include the interfaces I need.我已经导入了 mscoree.tlb 但它似乎没有包含我需要的接口。
The interfaces I'm interested in include IMetaDataEmit .我感兴趣的接口包括IMetaDataEmit 。 Any sample code relating to this would be very useful, though I've not been able to find any so far.
任何与此相关的示例代码都非常有用,但我目前还没有找到任何示例代码。
C# samples would be fine as I can easily convert them to F#. C# 示例很好,因为我可以轻松地将它们转换为 F#。
Thanks in advance to anybody who can help me with this rather cryptic query!提前感谢任何可以帮助我解决这个相当神秘的查询的人!
Update: I have now got this sorted by writing explicit COM references using the interface GUIDs!更新:我现在通过使用接口 GUID 编写显式 COM 引用来对此进行排序!
One option here would be to create your own project and compile these interfaces (using their definitions from cor.h) into a type library, which you could then tlbimp into a managed assembly.这里的一种选择是创建您自己的项目并将这些接口(使用它们在 cor.h 中的定义)编译到类型库中,然后您可以将其 tlbimp 转换为托管程序集。 I realize it would be pretty tedious to convert the C header code into IDL, but that could possibly be automated (or partially automated) by some text-processing scripts.
我意识到将 C 头代码转换为 IDL 会非常乏味,但这可能会由一些文本处理脚本自动(或部分自动)完成。
我希望您找到了mdbg 示例,其中包含用于准确包装您需要的接口的源代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.