简体   繁体   English

如何从 C# 或 F# 访问 IMetaDataEmit 和其他 MetaData COM 接口?

[英]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.

相关问题 将C#接口/类传递给F# - Pass C# interfaces/classes to F# 如何在C#中定义F#中的事件 - How do define an event in F# visible from C# 如何将 `where T : U` 泛型类型参数约束从 C# 转换为 F#? - How do I translate a `where T : U` generic type parameter constraint from C# to F#? 如何在 Visual Studio 中从 Go 到 C# 到 F# 的源代码定义(不是元数据)? - How to Go To Source Code Definition (not Metadata) from C# to F# in Visual Studio? 如何在不打开的情况下从F#调用C#扩展方法? - How do I call a C# extension method from F#, without open? 如何从C#可移植类库(PCL)添加对F#可移植库的引用 - How do I add a reference to F# Portable Library from C# Portable Class Library (PCL) 如何将受歧视的联合从C#传递给F#函数(F# - C#interop) - How to pass a discriminated union from C# to a F# function (F# - C# interop) 来自C#继承类的F#访问受保护字段 - F# access protected field from a C# inherited class F#类型提供者与C#接口+实体框架 - F# type providers vs C# interfaces + Entity Framework c#f#:WebApi:如何使用HttpRouteCollection执行与RouteCollection.RouteExistingFiles等效的操作? - c# f#: WebApi: How do I do the equivalent of RouteCollection.RouteExistingFiles with HttpRouteCollection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM