不幸的是,我不知道任何关于这个特定的DLL。但是,当您自己进行P/Invoke时,您可以应付一点重复,可以为每个平台创建一个代理。
例如,假设您有以下界面,应该由这两个一个32位或64位DLL中实现:
public interface ICodec {
int Decode(IntPtr input, IntPtr output, long inputLength);
}
您创建代理:
public class CodecX86 : ICodec {
private const string dllFileName = @"Codec.x86.dll";
[DllImport(dllFileName)]
static extern int decode(IntPtr input, IntPtr output, long inputLength);
public int Decode(IntPtr input, IntPtr output, long inputLength) {
return decode(input, output, inputLength);
}
}
和
public class CodecX64 : ICodec {
private const string dllFileName = @"Codec.x64.dll";
[DllImport(dllFileName)]
static extern int decode(IntPtr input, IntPtr output, long inputLength);
public int Decode(IntPtr input, IntPtr output, long inputLength) {
return decode(input, output, inputLength);
}
}
最后让一个工厂为你挑选合适的工厂:
public class CodecFactory {
ICodec instance = null;
public ICodec GetCodec() {
if (instance == null) {
if (IntPtr.Size == 4) {
instance = new CodecX86();
} else if (IntPtr.Size == 8) {
instance = new CodecX64();
} else {
throw new NotSupportedException("Unknown platform");
}
}
return instance;
}
}
由于第一次调用DLL时懒惰地加载了DLL,尽管每个平台都只能加载原生版本,但实际上它仍然有效。有关更详细的解释,请参阅this article。
我会说,大部分时间不打扰 - 除非你希望你的应用程序使用接近2GB的RAM只是让你的项目目标仅适用于x86,它只会在32位版本的scilexer.dll中运行。 – 2009-11-15 11:07:09