К сожалению, я ничего не знаю об этой конкретной 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 загружаются лениво при первом вызове, это на самом деле работает, несмотря на то, что каждая платформа может загружать только ту версию, которая ей присущи. См. эту статью для более подробного объяснения.