Hello All,
This question is related to my previous question - http://stackoverflow.com/questions/3632473/dynamically-running-a-dll-at-a-remote-windows-box First of all, thanks for all your helpful insights.
I have found a way to run a DLL at a remote machine.
Now what I am trying to do is as follows.
(1) send a DLL to the remote machine.
(2) send a command to the remote machine to run a function in the DLL.
A command may contain things like (a) DLL's location (2) function entry point (3) parameters.
The trouble is... in a given DLL, there could just be any functions with various return types and parameters.
Do you have any suggestions on how I could effectively bind a DLL function with unknown return types and unknown parameters? Should I just put a restriction on what kind of functions the remote machine can run?
Here is my code snippet in C#...
[DllImport("kernel32")]
public extern static IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32")]
public extern static Boolean FreeLibrary(IntPtr hModule);
[DllImport("kernel32")]
public extern static IntPtr GetProcAddress(IntPtr hModule, string procedureName);
// THIS IS THE PART THAT I HAVE A PROBLEM WITH.
// Since I want to bind MyFunction to just about any function in a DLL, I sure cannot declare the following as something like "double".
// Also there could just be any combinations of parameters (e.g. int, string, double..)
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate double MyFunction(int arg);