I have 2 unmanaged dlls which have exactly same set of function (but slightly different logic).
How can I switch between these 2 ddls during runtime?
now I have:
[DllImport("one.dll")]
public static extern string _test_mdl(string s);
Expanding on the existing answers here. You comment that you don't want to change existing code. You don't have to do that.
[DllImport("one.dll", EntryPoint = "_test_mdl")]
public static extern string _test_mdl1(string s);
[DllImport("two.dll", EntryPoint = "_test_mdl")]
public static extern string _test_mdl2(string s);
public static string _test_mdl(string s)
{
if (condition)
return _test_mdl1(s);
else
return _test_mdl2(s);
}
You keep using _test_mdl in your existing code, and just place the if-statement in a new version of that method, calling the correct underlying method.
Define them in different C# classes?
static class OneInterop
{
[DllImport("one.dll")]
public static extern string _test_mdl(string s);
}
static class TwoInterop
{
[DllImport("two.dll")]
public static extern string _test_mdl(string s);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With