I write the .net-extension which can be loaded into different versions of some unmanaged application.
Below I imported the some_func_v01
, some_func_v02
, and some_func_v03
functions:
[DllImport("some_library_v1.0.dll", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Unicode, EntryPoint = "func_name")]
extern static private void some_func_v01(string msg);
[DllImport("some_library_v2.0.dll", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Unicode, EntryPoint = "func_name")]
extern static private void some_func_v02(string msg);
[DllImport("some_library_v3.0.dll", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Unicode, EntryPoint = "func_name")]
extern static private void some_func_v03(string msg);
...
public void some_func(string msg)
{
switch (Application.Version.Major)
{
case 1: some_func_v01(msg); break;
case 2: some_func_v02(msg); break;
case 3: some_func_v03(msg); break;
}
}
The some_library
library is the part of the target application and has the same version like the application.
The problem is that I am to edit the code of my extension when the new versions of application will appear. I would like to dynamically generate code depending of application version. For example, for application version 1:
[DllImport("some_library_v1.0.dll", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Unicode, EntryPoint = "func_name")]
extern static private void some_func(string msg);
I can to do it through the PowerShell hosting using, but maybe more simple way exists... I wouldn't want to create PowerShell hosting only to carry out this task.
Is exist the simple way to do it?