我一直在尝试使用 Haxe 生成 C# 代码,该代码从用 C++/CLR 编写的 dll 中调用方法。这个dll被称为“AudioClientSDK.dll”
这是我正在尝试的 Haxe 代码的示例:
package hello;
class HelloWorld {
static public function main():Void {
var s = untyped __cs__("AudioClientCLR.AudioClientAPI.release()");
}
}
如您所见,我使用“Haxe magic”语法(我之前尝试过 Haxe extern 类,结果几乎导致了相同的问题)直接调用 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 的一些属性:
另外,请注意,在 Visual Studio 中使用 C# 可以毫无问题地使用此 dll。
这似乎是一个错误。请尽快将其报告到 haxe 问题列表,并提供有问题的 dll 的可下载链接,它可能会包含在 3.2 最终版本中
我知道这是一个非常老的问题,但有更好的方法来做到这一点(并且它应该可以与任何相对较新的 haxe 4 版本一起使用) 执行 --net-lib 操作来链接您的 DLL,然后它应该显示在导入上下文中,如下所示(命名空间自动变为小写):
import audioclientclr.AudioClientAPI;
function main() {
AudioClientAPI.release();
}