Reputation: 6717
During runtime i am supplied with a String
name, a sorted array of objects and some additional information about a native function (dllpath, calltype, etc).
lets assume all information was in a CallInformation
Object.
How can i call this native function?
note: - i am not supplied with the dll before runtime. - i am not supplied with the call information before runtime. - i dont know the ammount or types of call parameter before runtime. - i dont know the returntype before runtime.
The usual information on the web about calling native functions deals with invoking
What i need is
Upvotes: 3
Views: 212
Reputation: 3740
The solution would involve Reflection.Emit. You have to dynamically generate a class containing your PInvoke signature decorated with the appropriate DllImport attribute based on your CallInformation. Sorry that there is no code, but it can't be boiled down to something worthy to post, considering the verbose Reflection.Emit API.
Upvotes: 2
Reputation: 31579
Make a delegate signature dynamically and call it using reflection.
Just look up how to create delegates dynamically, how to load a native function, how to call a function using reflection and connect those together.
Upvotes: 1