不幸的是,我不知道任何關於這個特定的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