Is there a way to call an API in unmanaged DLL from C# application in a way that the name of the API

  • Thread starter Thread starter lingchen_email
  • Start date Start date
L

lingchen_email

Hi,

Is there a way to call an API in unmanaged DLL from C# application in a
way that the name of the API is generated programmatically?

For example, I have API_AAA(p1,p2) & API_BBB(p1,p2,p3) defined in an
unmanaged DLL already. I know that I can use DllImport and declare the
APIs as "public static extern ......", and then call API_AAA() &
API_BBB() directly from the C# code. But, what I really want is
something similar to Type.InvokeMethod() in C# so that I can call
either API_AAA() or API_BBB() by passing the function name in string
programmatically to the Invoke() call, and also generate the
corresponding parameter values dynamically into an args array.

Is this possible?

Thanks,
LingChen
 
Hi,

Is there a way to call an API in unmanaged DLL from C# application in a
way that the name of the API is generated programmatically?

For example, I have API_AAA(p1,p2) & API_BBB(p1,p2,p3) defined in an
unmanaged DLL already. I know that I can use DllImport and declare the
APIs as "public static extern ......", and then call API_AAA() &
API_BBB() directly from the C# code. But, what I really want is
something similar to Type.InvokeMethod() in C# so that I can call
either API_AAA() or API_BBB() by passing the function name in string
programmatically to the Invoke() call, and also generate the
corresponding parameter values dynamically into an args array.

Is this possible?

Thanks,
LingChen


Take a look at the TypeBuilder class in System.Reflection.Emit.

Willy.
 
Back
Top