Can Roslyn be used for VB.NET scripting? - vb.net

I'm creating a script editor for my application, and I'd like to have it be able to run both C# and VB.NET scripts using Roslyn. I got this working with C# by using the CSharpScript class in the Microsoft.CodeAnalysis.CSharp.Scripting assembly/namespace, however there is no equivalent VisualBasicScript class that I can find, nor a Microsoft.CodeAnalysis.VisualBasic.Scripting assembly. I've scoured the web and can find nothing useful about running VB.NET scripts, and all the samples on the Roslyn github site are C#-specific. Am I missing something, or does support for running VB.NET scripts simply not exist the way it does for C# scripts?

Visual Basic Scripting is not currently available, presumably because it's not finished.
But its source is is the Roslyn repo, so you could try building it yourself.
When I do that, code like the following works for me:
Dim result = VisualBasicScript.RunAsync("Dim result = 1+1").Result
For Each variable In result.Variables
Console.WriteLine($"{variable.Name}: {variable.Value}")
Next
But this code does not work for me (it fails when compiling the script):
Console.WriteLine(VisualBasicScript.EvaluateAsync("1+1").Result)
I'm not sure whether this is because it's not finished, or whether it's intentional difference from C# scripting.

Related

Running Data From External Classes

Over the past few months I have been struggling to find a way to execute external un-compiled classes from my program.
EXAMPLE:
I have a simple run button on a windows forum. When that run button is pressed I wan't to run the Main sub in run.vb. (Run.vb is not part of the program and is located in a directory)
Is their a way to do this without using .dll's?
You want to run VB.Net code as I see. There are a bunch of classes in System.CodeDom.Compiler namespace to deal with .Net source code.
See http://www.codeproject.com/Articles/5472/Compiling-NET-code-on-the-fly
There is a good example with explanation here.
If you want to run VB6 code, the only way is compiling it to dll and then dynamically load and run. Or you can use VBscript if it will suit you.
In fact, CodeDom compiles your code to dll assembly too, but keeps it in memory, so you don't need to clean up any mess after you app is dead

Loading (and executing) a lisp-file in autocad using .NET

I'm currently in the process of rewriting some old AutoCAD plugins from VBA to VB.NET. As it turns out, a (rather large) part of said plugin is implemented in LISP, and I've been told to leave that be. So the problem became running LISP-code in AutoCAD from .NET. Now, there are a few resources online who explain the process necessary to do so (like this one), but all of them takes for granted that the lisp-files/functions are already loaded. The VBA-function I'm currently scratching my head trying to figure out how to convert does a "(LOAD ""<file>"")", and the script is built in such a way that it auto-executes on load (it's a simple script, doesn't register functions, just runs from start to end and does it's thing).
So my question is. How can I load (and thus execute) a lisp-file in autocad from a .NET plugin?
Ok, there are two ways to sendcommand via .NET.
The first thing you need to understand is that ThisDocument doesn't exist in .NET.
ThisDocument is the document where the VBA code is written, but since your addin is document undependant, it stands alone and you must take the documents from the Application object.
You access the application with:
Autodesk.AutoCAD.ApplicationServices.Application
If you want to transform it to the same Application object as in VBA, with same methods and functions
using Autodesk.Autocad.Interop;
using Autodesk.Autocad.Interop.Common;
AcadApplication App = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
The first application has MdiActiveDocument, from where you can call the Editor and send written commands, or call the SendStringToExecute as said in other answer.
The AcadApplication has ActiveDocument (an AcadDocument object that behaves exactly as in VBA).
This document will have the same SendCommand your VBA has, use it the same way it's done in VBA.
If you can explain better the autoexecute part, I can help with that too.

gecko in vb.net, objectreference needs objectinstance?

I want to implement a Webbrowser in my vb.net (2008)-project, however, I don't like the inbuilt IE.
I also remembered that is was kind of easy to implement a mozilla-tool like the gecko-webbrowser in the past...
It was kinf of more complicated than I remember, as I had to dwnload xulrunner and Skybound.Gecko.dll which both probably have to be included in any publishing of the finished project... I also defined x86 as target CPU and made all the needed steps to use a GeckoWebBrowser within my Application. I also called Skybound.Gecko.Xpcom.Initialize(My.Application.Info.DirectoryPath & "/xulrunner") before compiling it.
However, when I try GeckoWebBrowser1.navigate("http://...") (The element was inserted with this name per designer) the IDE tells me that an objectreference is not set to a objectinstance as if GeckoWebBrowser1 isn't defined yet... but the GeckoWebBrowser1.Created attribute is giving back true.
Does anybody know why it isn't working yet?
I have the same error in my solution. Try to use GeckoFX assembly. I use 15 version dll and error fix.
https://bitbucket.org/geckofx/geckofx-16.0/downloads

How to run Powershell scripts in VB.Net

I need to run an Exchange 2007 powershell script in VB.Net, but I can't seem to find a method that shows how to do it with the module loaded.
What is the best method to do this?
You can run powershell scripts in VB, take a look at the following link
http://blogs.msdn.com/b/zainnab/archive/2008/07/26/calling-a-powershell-script-from-your-net-code.aspx
The link posted above takes you step by step on how to accomplish this.
Check out this question that relates to yours:
Running powershell scripts from within a .NET windows app
This following article is in C# but should help you understand the concept a bit better:
http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C
For VB.NET try this code:
Process.Start("powershell", "-File C:\YourFileLocation")
Basically, all you're doing is calling PowerShell and specifying an argument (the location of the cmdlet you're calling).

Monitoring application calls to DLL

In short: I want to monitor selected calls from an application to a DLL.
We have an old VB6 application for which we lost the source code (the company wasn't using source control back then..). This application uses a 3rd party DLL.
I want to use this DLL in a new C++ application. Unfortunately the DLL API is only partially documented, so I don't know how to call some functions. I do have the functions signature.
Since the VB6 application uses this DLL, I want to see how it calls several functions. So far I've tried or looked at -
APIHijack - requires me to write C++ code for each function. Since I only need to log the values, it seems like an overkill.
EasyHook - same as 1, but allows writing in the code in .NET language.
OllyDbg with uHooker - I still have to write code for each function, this time in Python. Also, I have to do many conversions in Python using the struct module, since most functions pass values using pointers.
Since I only need to log functions parameters I want a simple solution. Is there any automated tool, for which I could tell which functions to monitor and their signature, and then get a detailed log file?
A "static" solution (in the sense it can capture a stack trace on demand) would be Process Monitor.
A more dynamic solution would be ApiMonitor, but it may be too old to be compatible with the applications to monitor. Worth a try though.
Some more Google searching found what I was looking for: WinAPIOverride32. It allows writing text files such as:
CustomApi.dll|void NameOfFunction(long param1, double& param2);
Later on, these files can be used inside the program to log all calls to NameOfFunction. Now I just need to figure out how to log arrays and structs parameters.
Visual Studio Addin Runtime Flow here:
Runtime Flow in real time monitors and logs function calls and
function parameters in your running .NET application and shows a stack
trace tree. No instrumentation or source code required for monitoring.
If you just want to see the function interfaces of the DLL, you could try "Dependecies" (https://lucasg.github.io/Dependencies/). This is a nice remake of the DependencyWalker in as OpenSource.
This only allows you to see the dependencies of the DLL, with the corresponding function names (however, not the calling structure). Unfortunately, I don't believe it will tell you which specific functions in a DLL are being used by the calling DLL/EXE.