KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: [Solved] Possible to call .NET DLL from Dragon script?
Topic Summary: TL;DR No, with the caveat that indirect access can be an option (wrap the DLL and call the wrapper)
Created On: 04/07/2019 05:25 AM
Status: Post and Reply
Linear : Threading : Single : Branch
 [Solved] Possible to call .NET DLL from Dragon script?   - locution - 04/07/2019 05:25 AM  
 Possible to call .NET DLL from Dragon script?   - Mphillipson - 04/09/2019 11:57 AM  
 Possible to call .NET DLL from Dragon script?   - monkey8 - 04/11/2019 04:38 AM  
 Possible to call .NET DLL from Dragon script?   - locution - 04/12/2019 10:43 AM  
 [Solved] Possible to call .NET DLL from Dragon script?   - PG LTU - 04/12/2019 12:06 PM  
 [Solved] Possible to call .NET DLL from Dragon script?   - locution - 04/12/2019 12:27 PM  
Keyword
 04/07/2019 05:25 AM
User is offline View Users Profile Print this message

Author Icon
locution
Senior Member

Posts: 124
Joined: 02/27/2019

Howdy everyone,

I had started this question on a different thread but am moving it here to make it easier to find and so I can mark the other thread "Solved". The question:

Have you had success using Reference (or other means) to call a .NET DLL?

Looking forward to your thoughts on this one.

 

--

Here is what we have so far.

 

1.

 

Originally posted by: PG LTU To use References you right click in the command editor and select the one you want. The IDE does not show the reference comment, but export as .xml and you can see.

 

2.

 

Originally posted by: locution
Originally posted by: PG LTU To use References you right click in the command editor and select the one you want. The IDE does not show the reference comment, but export as .xml and you can see.

 

Wow okay this is hugely convenient.

 

Let's see if I understand. I want to use Regex.Match.The page in the link says:

 

Assemblies: System.Text.RegularExpressions.dll, System.dll, netstandard.dll

 

So I create a new Advanced Script, right.click, select Reference, and check the box next to System 2.4. However, netstandard.dll is not on the list.

 

Is this a step in the right direction?

 

3.

 

Originally posted by: Mphillipson I don't believe you can call a .net library from Advanced Scripting. Although KnowBrainer does support this functionality. You can however call COM Objects. If you follow the link on my signature. There somewhere is a example of a script that calls a database. I use this for things like Custom IntelliSense so I can insert snippets of code or whatever in any application by calling up a list of them. Or a list of folders. I also have a list of applications to launch under several different categories. And even entering usernames and passwords. I find keeping all the variable information in the database saves me from constantly editing scripts.

 

4.

 

Originally posted by: PG LTU Can you browse to it? I have a couple of MS VBS RegEx implementations (1.0 and 5.5, whatever that means) which expose VBScript_RegExp_55.Match and other stuff (once you add it, the object browser will show its properties and methods).

 

5.

 

Originally posted by: locution Thanks to you both for your replies, learning HEAPS on this thread, excited!

 

@Mark

That's a huge file of scripts you have there on GitHub! Saved for future reference, thank you for sharing your work. After a very quick glance inside the file, I see lots of "Case switching" to assign variables, does this mean you're not a fan of the "canonical\Spoken Form" way of defining lists, and if so would you be willing to share your rationale?

 

@PG

> Can you browse to it?

Yes, there are copies of various versions in a number of places, for instance:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Web.RegularExpressions.dll

 

You mentioned VBScript, sadly that regex flavor is really crude (no conditionals!, no inline flags and more importantly no utf-8), I don't want to go there, but the .NET flavor rocks. One of the only flavors out there with infinite lookbehind — and lots of cool goodies.

 

(Another option would be to call a Python script, where it's possible to import the MRBarnett regex library which is also outstanding. But that's a similar approach to what I'm already doing in AHK, and at the moment I'm really curious about direct access to the .NET functions, as that would probably speed things up considerably.)

 

 

 



 04/09/2019 11:57 AM
User is offline View Users Profile Print this message

Author Icon
Mphillipson
Top-Tier Member

Posts: 297
Joined: 09/22/2014

As far as I am aware you can only use COM Objects from Advanced Scripting.

You can however create VB.net scripts using KnowBrainer.

-------------------------

Thanks Mark


 


Dragon Professional Advanced Scripting/KnowBrainer Scripts
Video Examples of Coding by Voice

 04/11/2019 04:38 AM
User is offline View Users Profile Print this message

Author Icon
monkey8
Top-Tier Member

Posts: 3904
Joined: 01/14/2008

What Mark has told you is pretty much correct. In order to access the Regex RegularExpressions.dll you need to run.net scripting which is only possible from KnowBrainer. This is because .net requires a virtual machine runtime called the CLR which you can look up on Google. It is the equivalent of Java runtime environment for Java. Advanced scripting allows access to COM objects only whereas KnowBrainer scripting allows access to COM and .net which is why I included it with KnowBrainer in the first place. Lastly KnowBrainer uses a much later version of the scripting engine that Advanced Scripting uses and it is therefore much faster. It is also faster than DvC.



-------------------------



 04/12/2019 10:43 AM
User is offline View Users Profile Print this message

Author Icon
locution
Senior Member

Posts: 124
Joined: 02/27/2019

Hi Mark and @monkey8,

 

Thank you both for your helpful and hugely informative replies!

 

Given what you said, I'm going to mark the question as "Solved", the answer being a general "No", but with the caveat that indirect access to the library can sometimes be an option.

 

For instance, for the .NET library I wanted to use, I wrapped the function into a little C# command-line utility that accepts command-line parameters, and calling it works great from Dragon scripting.

 

That being said, the limitation is getting things out of the function. For the time being the best way I've found is the hack of placing the output on the clipboard, with later clipboard restoration. Other hacky ways seem possible (writing to a file, to the registry, to an environment variable... haven't figured out a way with STDOUT) but [Not A Complaint]none of those are a as  satisfying as a direct call would be.[/Not A Complaint]

 04/12/2019 12:06 PM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2210
Joined: 03/21/2007

Uhm, this is not an ahk forum (funny me saying that) but surely you looked at the help and saw the penultimate example on the "Run" page which explains how to use WScript.Shell.Exec to do what you want (return stdout to your ahk script). By the way, this is also how you do it in .js and .vbs so wonder where the problem is? To get you started, see: https://autohotkey.com/docs/commands/Run.htm

; with my edits (it works better w params my way):
RunWaitOne(command) {
    shell := ComObjCreate("WScript.Shell")
    exec := shell.Exec(ComSpec " /C """ command """") ; added '"' around command to allow params
return exec.StdOut.ReadAll()
}



Hth!



-------------------------




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.



 04/12/2019 12:27 PM
User is offline View Users Profile Print this message

Author Icon
locution
Senior Member

Posts: 124
Joined: 02/27/2019

@LG actually that was not an AHK question, sorry if that wasn't clear. The .NET library that I wrapped is a binary that I call directly from Dragon scripting, and it is in this context that I was ruminating about standard out…

 

But all the same, very glad to have your precious input about doing this in AHK, and if I understand you correctly, the same approach can be used from within a Dragon script… Will try that out. Thank you!

Statistics
32324 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 0 users logged in.
The most users ever online was 12124 on 09/09/2020 at 04:59 AM.
There are currently 388 guests browsing this forum, which makes a total of 388 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2022 FuseTalk™ Inc. All rights reserved.