Is it possible to call QM from other programs and batch files? QM is kind of an "object" that has lots of capabilities, so I would like to call it from other programs as if it was a QM "service."
One way I'd like to use it is from a batch file, where I would call it like any other program:
rem call qm from a DOS .BAT file
quickmacros -macroname my-macro-name1
Another way is to call it from Basic as a COM object, using the GetObject call. I'm really interested in this one!
sub main
Dim qm as object
set qm = GetObject(, "quickmacros.application")
qm.Run ("my-macro-name-1")
set qm = nothing
end sub
A third way would be to reference a quick macros DLL from a Visual Studio project, Excel sheet, Word macro, ... etc.
Is any of this possible, or does QM have to be the top-level boss program that initiates all macros on the basis of user inputs or windows/OS triggers? Thank you.
I'm just getting started on reading the doc and watching the youtube videos, so please forgive me if the answer is somewhere deeper in the documentation. I haven't seen mention of it so far. Thank you
No COM, no dll, only command line.
Command line text can be created in the Properties dialog, button Cmdline. More info in QM Help topic "Command line parameters".
I'm sorry to hear that no COM interface is available. It would have been wonderful to be able to call QM from other programs. QM has a huge amount of functionality, and it would be useful if other programs could call the macros inside QM. I suppose I could export macros into EXE files and call them through ShellExecute, but that is a crude method and comes with a (temporary) flashing Command Prompt window. Or I could make a BAT file to call QM from the command line and call the BAT file from my other programs with ShellExecute. But still, those are crude methods compared to calling a COM GetObject interface (which seems easy to do for a person of your very advanced skill). Was there a reason or two that you decided not to provide a TLB / COM interface to some of QM's functionality? Thank you
Macros can be executed from any program with ShellExecute or CreateProcess using the command line, directly without bat or command prompt, synchronously or not.
Reason - not many QM users wanted it, so I worked in other directions.
Next major QM version will have a free .NET dll. But not soon.
(03-07-2018, 07:24 PM)Gintaras Wrote: Macros can be executed from any program with ShellExecute or CreateProcess using the command line, directly without bat or command prompt, synchronously or not.
Reason - not many QM users wanted it, so I worked in other directions.
Next major QM version will have a free .NET dll. But not soon.
Thank you. In my case, I was hoping to call QM from the Basic ShellExecute available in Dragon NaturallySpeaking. It is a very limited ShellExecute that does not allow use of nShowCmd to avoid the flashing command prompt window. I suppose I can write my own DLL to implement the chain Dragon -> Basic -> GetObject ("my DLL") -> ShellExecute/CreateProcess -> QM -> macro. I was just hoping that you had a COM interface built over the years. Thank you for your reply.
PS. If I am running an instance of QM and have another program that calls QM on the command line some way, will the running instance of QM interfere with the second QM that is invoked from a batch file? Or if I am running QM and then manually invoke a batch file that calls QM to run a macro, will the two QM instances interfere with each other? Thank you
No, qm always has only 1 normal process (instance). Other qm or qmcl process relays the command line to the main process and exits (qmcl also can wait).
This .NET/COM dll can be used to run macros in QM from other programs and scripts.
Where can be used
In any programming/scripting language through COM.
In C# and other .NET languages directly.
In 32-bit and 64-bit processes.
Setup
The dll uses .NET framework 4. Can be installed any 4.x.x version. If not installed, download from Microsoft and install.
Download the attached zip file. Extract anywhere, for example in QM folder.
Register the dll, unless you'll not use it as a COM component. To register, you can use regasm.exe or this QM code. Note: if you have an old RegisterNetComComponent function, need to update it.
Macro Macro35
int i for i 02 ,int ec=RunConsole2(cl so) ,errend _error ,so.trim ,if(ec)end so ,if(so.len)out so ,if(i or!_win64)break ,cl.findreplace("\Framework\""\Framework64\"5)
How to use in scripts etc
Create COM object "QmSendMessage.QMSM".
To run a macro or function, call the Run function with QM command line, like in the example.
using System;
using System.Runtime.InteropServices;
[module: DefaultCharSet(CharSet.Unicode)]
//these can be in AssemblyInfo.cs, or here if you don't use it:
//[assembly: ComVisible(true)]
//[assembly: Guid("2cd050a0-8337-4d80-b548-56af5b16de04")]
//Also, in project properties, assembly name and default namespace is QmSendMessage, platform can be AnyCPU.
[Guid("BAB07F95-1558-47C6-A6AA-0127BB8F6799"), ClassInterface(ClassInterfaceType.None)]
public class QMSM :IQMSM
{
public void Run(string commandLine, bool wait)
{
var w = FindWindow("QM_Editor", null);
if(w == default(IntPtr)) throw new InvalidOperationException("QM is not running");
SendMessage(w, WM_SETTEXT, (IntPtr)(wait ? 2 : 1), commandLine);
}