简体   繁体   English

在 F# 中导入/打开 DLL

[英]Import/open DLLs in F#

I want to know if there any possibility to import/open DLLs in F# (binary, not script).我想知道是否有可能在 F#(二进制,不是脚本)中导入/打开 DLL。

open SDL2

By the way this is one of my first question on stackoverflow, don't hesitate to ask me more details.顺便说一句,这是我关于 stackoverflow 的第一个问题,请不要犹豫,问我更多细节。

open... opens a namespace/module. open...打开一个命名空间/模块。 It does not reference an assembly.它不引用程序集。

Assuming you are intending to use a C#/.NET version of SDL2 you will need to reference that assembly.假设您打算使用 C#/.NET 版本的 SDL2,您将需要引用该程序集。 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 do.net add package <packagename> .如果它作为 nuget package 可用,则可以将其添加为 visual studio 中的依赖项(在依赖项上下文菜单中manage nuget packages )或使用以下命令行do.net add package <packagename> If it is not a nuget package, then you can still reference the assembly directly.如果不是nuget package,那你还是可以直接引用程序集。 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.在 visual studio 中,您应该能够 select 在依赖项上下文菜单中add project reference ,之后您可以 select 浏览到 select 您要使用的 dll。

You can also add DLL file directly to your project file.您也可以将 DLL 文件直接添加到您的项目文件中。 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:首先将DSL2.dll复制到一个已知位置,例如项目文件夹中的lib文件夹(如果需要,带有依赖项),然后编辑项目文件以包含以下内容:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM