在 F# 中导入/打开 DLL [英] Import/open DLLs in F#

查看:31
本文介绍了在 F# 中导入/打开 DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能在 F#(二进制,而不是脚本)中导入/打开 DLL.

I want to know if there any possibility to import/open DLLs in F# (binary, not script).

open SDL2

顺便说一下,这是我关于 stackoverflow 的第一个问题之一,不要犹豫,问我更多细节.

By the way this is one of my first question on stackoverflow, don't hesitate to ask me more details.

推荐答案

open ... 打开一个命名空间/模块.它不引用程序集.

open ... opens a namespace/module. It does not reference an assembly.

假设您打算使用 SDL2 的 C#/.NET 版本,您将需要引用该程序集.如果它作为 nuget 包可用,那么您可以将其添加为 Visual Studio 中的依赖项(manage nuget packages 在依赖项上下文菜单中)或使用以下命令行 dotnet add package <;包名>.如果它不是nuget包,那么您仍然可以直接引用程序集.在 Visual Studio 中,您应该能够在依赖项上下文菜单中选择 add project reference,然后您可以选择浏览以选择要使用的 dll.

Assuming you are intending to use a C#/.NET version of SDL2 you will need to reference that assembly. If it is available as a nuget package, then you can add it as a dependency in visual studio(manage nuget packages in dependencies context menu) or use the following command line dotnet add package <packagename>. If it is not a nuget package, then you can still reference the assembly directly. In visual studio you should be able to select add project reference in the dependencies context menu after which you can select browse to select the dll you want to use.

您也可以将 DLL 文件直接添加到您的项目文件中.首先将 DSL2.dll 复制到一个已知位置,例如项目文件夹中的 lib 文件夹(如果需要,还有依赖项),然后编辑项目文件以包含以下内容:

You can also add DLL file directly to your project file. First copy DSL2.dll into a know location such as lib folder inside project folder (with dependencies if needed), then edit project file to include the following:

<ItemGroup>
  <Reference Include="SDL2">  <!--the name here can be anything-->
    <HintPath>lib\SDL2.dll</HintPath>
  </Reference>
</ItemGroup>

之后,您应该能够打开命名空间(open SDL2)或使用其完全限定名称(例如 let x = SDL2.SDL)直接调用各种函数/类型.SDL_...)

After that you should be able to open the namespace(open SDL2) or directly call the various functions/types by using its fully qualified name(e.g. let x = SDL2.SDL.SDL_...)

这篇关于在 F# 中导入/打开 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆