Load DLL with parameters - vb.net

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.

Related

How to apply more than one function to a passed in live template variable?

I'm trying to build a Python Unit Test File Template in PyCharm. The overall result I want to achieve is:
A user creates a new file with my template, say "widget_builder.py"
Inside the template I want to create the class name by taking the file name "widget_builder" and turning it into "WidgetBuilderTests"
It looks like I need to use a Live Template to manipulate the file template variable $FILE_NAME$?
How can I create a Live Template that given a passed in variable (in this case $FILE_NAME$), applies both the underscoresToCamelCase and capitalize functions to it?
If I declare the Template text as:
$CLASS_NAME$
...and then edit variables, how can I reference a passed in variable of '$FILE_NAME$'?
I'd imagine it to look something like this, but I just can't get it to work:
I'm sure there must be a way to do this, but I just can't quite wrap my head round it.
Is this possible? Thanks!
EDIT
I've got a bit further. If I define the template as this:
If I then use it, this happens:
So the end result of $CLASS_NAME$ (WidgetBuilder) on the left is what I want, but I don't want $FILE_NAME$ (widget_builder) to be there once I hit return.
So your problem here is that $FILE_NAME$ is not a native variable in the live templates, merely an arbitrary name. What you actually want to be using is another function: fileNameWithoutExtension().
So your template would look something like:

How to create source code with dynamic FM creation

I'm using FUNCTION_CREATE to create FM and everything is working fine, I'm passing bunch of parameters and FM is created like it should. But the problem is the Source Code part of FM. Is it possible to create it with FUNCTION_CREATE and which parameter should I use?
Thanks
If you want to create function modules with the source code, then you need to use RS_FUNCTIONMODULE_INSERT as it has a source parameter.

Getting current file

I know in vb.net you can use System.Reflection.MethodInfo.GetCurrentMethod.ToString to get the name of the current method you are in. However, is there a way to use System.Reflection... to get the name of the current file you are in?
So if you had a file in the project named blah.vb I would want System.Reflection... to return blah.vb
Is this possible?
You can use System.Reflection.Assembly to find the file name of the current assembly. There are several applicable methods to choose from:
GetEntryAssembly - Returns the assembly that started the process (the executable)
GetCallingAssembly - Returns the assembly that called the current method
GetExecutingAssembly - Returns the assembly in which the current method resides
I suspect that what you want is GetExecutingAssembly. All of those methods return an Assembly object through which you can get the file path, like this:
Dim myFilePath As String = System.Reflection.Assembly.GetExecutingAssembly().Location
For what it's worth, if you need get the file name of the executable, but it's not a .NET assembly (because you're in a .NET library invoked via COM), then the above method won't work. For that, the best option would be to grab the first argument from the command line, like this:
Dim myComExeFile As String = Environment.GetCommandLineArgs()(0)

SciLab: where do functions live / need to live?

I'm learning SciLab and I need to figure out the equivalent from MATLAB for running user-defined functions.
I'm used to MATLAB, where when you type foo(27), it looks for the foo.m script in the current directory and then the MATLAB path, and if it finds one, it calls that function with argument 27.
What's the equivalent to SciLab? It doesn't seem to want to look in the current directory for the appropriate .sci file.
In Scilab, you need to explicitly load the script that contains the function. Assuming you've changed your directory to the directory where the function file is loaded, which can be done in Scilab using the menu buttons or the following command:
cd("path/to/working/directory")
Now you load the function file. Assuming the function foo is stored in a file called foo.sci, you need to load this script using the following command:
exec("foo.sci")
Now you should be able to use your function as you would be able in MATLAB.
foo(27)

Calling any dll function based on variable arguments

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.