Haxe:如何在Haxe代码中使用.NET C++/CLI dll?

3

我将尝试使用Haxe生成调用C++/CLR编写的dll中方法的C#代码。该dll名为“AudioClientSDK.dll”。

以下是我正在尝试的Haxe代码示例:

package hello;

class HelloWorld {

    static public function main():Void {
        var s = untyped __cs__("AudioClientCLR.AudioClientAPI.release()");
    }
}

正如您所看到的,我正在使用"Haxe魔法"语法(之前尝试使用外部类也遇到了相同的问题),直接调用AudioClientSDK.dll中的release方法。在dll内的方法签名为:

public : void AudioClientCLR::AudioClientAPI::release()

然而,当我尝试编译这段代码时,Haxe会抛出以下错误:
haxe -cp src -cs out/CS -main hello.HelloWorld
haxelib run hxcs hxcs_build.txt --haxe-version 3103
c:\git\HelloHaxe\src\hello\HelloWorld.hx(6,16): error CS0103: The name
        'AudioClientCLR' does not exist in the current context
Compilation error
Native compilation failed
Error: Build failed

如果我试图将AudioClientSDK.dll参考作为-net-lib或-net-std传递,我会得到以下错误:
haxe -cp src -cs out/CS -net-lib lib/CPP/x86/AudioClientSDK.dll -main hello.HelloWorld
File "ilMetaReader.ml", line 281, characters 36-42: Assertion failed
error 0x2

haxe -cp src -cs out/CS -net-std lib/CPP/x86/AudioClientSDK.dll -main hello.HelloWorld
Error: No .NET std lib directory with the pattern 'net-20' was found in the -net-std search path. Try updating the hxcs lib to the latest version, or specifying another -net-std path.

你们中有人知道如何正确使用dll吗?
提前致谢。
附:AudioClientSDK.dll的一些属性:
- 目标框架:.NET Framework,版本=v4.0 - 平台:Win32 - 平台工具集:VisualStudio 2010(v100) - MFC的使用:使用MFC在共享DLL中 - 公共语言运行时:公共语言运行时支持(/clr)
另外,请注意这个dll可以在Visual Studio中的C#中无问题地使用。

你有检查过这个问题吗?看起来应该是Haxe 3.2.0 RC的一部分。你试过了吗? - JensG
非常感谢JensG,我刚刚安装了Haxe 3.2.0.RC,但仍然遇到了相同的问题:$ haxe -cp src -cs out/CS -net-lib lib/CPP/x86/AudioClientSDK.dll -main hello.HelloWorld File "ilMetaReader.ml", line 577, characters 34-40: Assertion failed error 0x3$ haxe -cp src -cs out/CS -net-std lib/CPP/x86/AudioClientSDK.dll -main hello.HelloWorld Error: No .NET std lib directory with the pattern 'net-20' was found in the -net-std search path. Try updating the hxcs lib to the latest version, or specifying another -net-std path. - Edgardo Gonzalez
2个回答

0

这似乎是一个bug。请尽快将其报告给Haxe问题列表,并提供有关有问题的dll的可下载链接,它可能会被包含在3.2最终版本中。


非常感谢您,Waneck,我刚刚打开了这个问题。http://github.com/HaxeFoundation/haxe/issues/4154 - Edgardo Gonzalez

0
非常老的问题,我知道,但有一种更好的方法来做到这一点(并且它应该在任何相对较新的Haxe 4版本中正常工作)。 使用--net-lib命令将您的DLL链接起来,然后它应该在导入上下文中显示出来,类似于这样(命名空间会自动变为小写):
import audioclientclr.AudioClientAPI;

function main() {
    AudioClientAPI.release();
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接