我将尝试使用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 -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