Hi, I have 2 unmanaged dlls wich have exactly same set of function (but slighly 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);
Hi, I have 2 unmanaged dlls wich have exactly same set of function (but slighly 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);
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);
}
I haven't ever had to use this, but I think the EntryPoint can be specified in the declaration. Try this:
[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);
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.