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

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
 
W

Willy Denoyette [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top