Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
F# 从F调用在VB6中创建的dll#_F#_Interop_F# 3.0 - Fatal编程技术网

F# 从F调用在VB6中创建的dll#

F# 从F调用在VB6中创建的dll#,f#,interop,f#-3.0,F#,Interop,F# 3.0,我试图从F#调用在vb6中创建的dll文件。我已经编写了以下dll 公共函数addTwoNumber(ByVal a为整数,ByVal b为整数) AddTwoNumber=a+b 端函数 现在我想在我的F#程序中调用它,我写了这段代码 open System.Runtime.InteropServices module InteropWithNative = [<DllImport(@"C:\add", CallingConvention = CallingConvention

我试图从F#调用在vb6中创建的dll文件。我已经编写了以下dll

公共函数addTwoNumber(ByVal a为整数,ByVal b为整数)
AddTwoNumber=a+b
端函数
现在我想在我的F#程序中调用它,我写了这段代码

open System.Runtime.InteropServices

module InteropWithNative =
   [<DllImport(@"C:\add", CallingConvention = CallingConvention.Cdecl)>]  
   void AddTwoNumbers(int, int)

InteropWithNative.AddTwoNumbers(3,4)

let result = AddTwoNumbers_ 2.0 3.0
open System.Runtime.InteropServices
模块互操作=
[]  
void addTwoNumber(int,int)
InteropWithNative.AddTwoNumber(3,4)
让结果=addTwoNumber_u2.0 3.0

它给了我错误并且无法识别函数。

一个具有入口点的工作互操作示例

open System.Runtime.InteropServices // for DllImport

module KernelInterop = 
    [<DllImport("kernel32.dll", EntryPoint="Beep")>]
    extern void Beep( int frequency, int duration )

KernelInterop.Beep  // val Beep : int * int -> unit
KernelInterop.Beep(440, 1000)
DllImport的open System.Runtime.InteropServices// 模块KernelInterop= [] 外部无效蜂鸣音(整数频率,整数持续时间) KernelInterop.Beep//val Beep:int*int->unit KernelInterop.Beep(4401000)
请至少说明错误实现文件中预期的关键字“void”不完整的结构化构造在定义中的这一点或之前似乎(至少)错过了前面的
void
(这不应该是
void
而是
int
,因为VB代码不是一个主题,出于好奇,为什么要尝试在古老的VB6中创建库?最好将任何现有的VB6转换为VB.NET,以便直接调用方法,或者如果需要本机代码,请切换到另一种语言。定义EntryPoint=“AddTwoNumbers”在[]@Functional_S>中,上面的代码运行良好,我玩了它。但是我如何使用它来回答这个问题,打开System.Runtime.InteropServices模块InteropWithNative=[]void AddTwoNumbers(int,int)InteropWithNative.AddTwoNumbers(3,4)let result=AddTwoNumbers\u2.0 3.0 ConsoleApplication32.exe中发生类型为“System.BadImageFormatException”的未处理异常。其他信息:试图加载格式不正确的程序。(HRESULT中的异常:0x8007000B)这可能会有所帮助[:>我读了这篇文章。它只关注将编译器模式从x64更改为x84。之后,我尝试运行代码,但仍然得到相同的错误。请在您的系统上测试它,以查看..module InteropWithNative=[]extern int32 AddTwoNumbers(int32 a,int32 b)let result=InteropWithNative.AddTwoNumbers(2,5)printf“结果是:%d”结果