Calling any dll function based on variable arguments - dll

I have the following items in a structure:
- Dll name (absolute/relative path)
- Function name in the dll
- number of parameters
- Array of parameter types and values
With this information, I need to load the dll and call the function.
To load the dll I would use LoadLibrary.
To get the address of the function I would use GetProcAddress.
Call the function.
To unload the dll, FreeLibrary
Since the number of arguments of the function is dynamic, I am not sure about how the arguments need to be passed to the function.
Can anyone provide some details on how the parameters can be passed to the dll function?
Thanks and Regards,
V Karthick

Is it possible to pass the dictionary object (the one with the parameters) to some wrapper function and have that wrapper function call the actual function? It would probably save you a lot of headache and you could potentially use the preprocessor to generate the wrapper functions for you.

Related

C# to Vb.NET code convert

below code is c#
ctx.CreateStreamResponse(stream => new Session(_Sessions, stream).Process(),"video/mp4");
and i need to this code as VB.NET code. am converting as below
ctx.CreateStreamResponse(Function(stream) New Session(_Sessions, stream).Process(), "video/mp4")
But getting error
overload resolution failed because no accessible
"CreateStreamResponse" can be called with these arguments.
CreateStreamResponse needs 2 parameters
Stream (as my sample Function(stream) New Session(_Sessions, stream).Process())
content type (as my sample "video/mp4")
Anyone can help me, please
I believe the issue seems to be that the method which you pass into CreateStreamResponse should be a Sub not a Function. i.e:
ctx.CreateStreamResponse(Sub(stream) New Session(_Sessions, stream).Process(), "video/mp4")
CreateStreamResponse takes an Action(Of Stream) delegate as the first argument and a contentType of String as the second argument.
Thus you need to use Sub rather than a Function as in this case an Action delegate can only encapsulate methods that return void (sub procedures). Also, ensure that the Process method being invoked is also a Sub procedure.
If the problem persists then as suggested by Microsoft docs:
Review all the overloads for the method and determine which one you
want to call.
In your calling statement, make the data types of the arguments
match the data types of the parameters defined for the desired
overload. You might have to use the CType Function to convert one or
more data types to the defined types.
for more information see here

How to access the event arguments passed to a ColdBox module?

I have a view in my ColdBox application that is calling a module handler within the view like this:
#runEvent( event="mymodule:home.index" )#
Now I want to pass arguments to the module, so I changed the call to this:
#runEvent( event="mymodule:home.index", eventArguments=moduleArgs )#
Though unfortunately I don't seem to have access to the passed arguments within the module's event handler. I've dumped rc and prc, but they only contain variables I've set in the main event handler and the event argument doesn't seem to provide a method to return the passed arguments. The documentation about module event executions unfortunately doesn't provide any information about this.
Also, I realized calling event.getCurrentModule() within the module returns an empty string. I would have expected the module's name.
So, how can I access the arguments passed to a module? Is runEvent() the right function for this? Did I miss a module config setting?
You can define arguments in your function like this
function index(event, rc, prc, isRender=false) {
writedump(arguments);
abort;
}
See the ColdBox runEvent() documentation.
The ColdBox documentation explains how to pass additional arguments to your function. So e.g. calling
#runEvent( event="mymodule:home.index", eventArguments={foo="bar"} )#
the foo variable can be accessed via the arguments scope:
function index(event, rc, prc) {
writedump(arguments.foo); // Dumps "bar"
}

Call function from DLL based on some dynamic determined ordinal?

Can I call a function from LabVIEW that is at certain ordinal in some DLL, while the ordinal is determined at run-time?
I'm also interested if there is something similar to function pointers, like in 'C' language, which hold some dynamic function address?
If your intention is to call function by address, you will have to develop a wrapper in C by compiling a DLL from a code like that:
typedef int (*real_func_type)(int);
int wrapper(size_t address, int param1)
{
return ((real_func_type)address)(param1);
}
where real function proto is
int real_func(int param);
If your second question is whether LabVIEW has something similar to a function pointer, then the answer is that the closest thing is a VI reference. There are different types of VI references and different ways of creating and using them, so you would need to read up on that.
In any case, VI references are purely a LabVIEW construct. There's no mechanism for interacting with C function pointers directly and you can't create a function pointer to a VI and give that to the DLL function. For something like that you would also need some wrappers.
In your block diagram, create a case structure that takes your ordinal value. In each frame of the case structure, invoke the appropriate function from the DLL.

Load DLL with parameters

I need to delete every single function from my project (VB.Net) and place them in separate DLLs. For example, i have a function that creates a text file and appends text to it. I need a solution that will load my AppendToTextFile.DLL with params just like a function works.
At this time my function accepts two parameters like
AppendToTextFile("C:\test\textFile.txt", "text to be appended")
Does anyone know how to load a custom DLL with params like the function above?
Create your custom DLL.
Then add it as reference to your project.
Call you function and use it like this :
Dim mydll As New MyCustomeDll
mydll.AppendToTextFile("C:\test\textFile.txt", "text to be appended")
That's all.

Resolving a MATLAB class method handle using the method name alone

I'm trying to call a method within a class, assuming I only know its name (aka, a char vector with its name)
I tried calling str2func(['obj.' functionName]) - where functionName is the name of that method, without any luck - I can't seem to grab the handle of the method.
You can reference it like a field
obj.(functionName)
or using feval
feval(functionName, obj, ...)
I recommend the first option.