Posts: 3
Threads: 2
Joined: Mar 2022
03-08-2022, 04:53 AM
(This post was last modified: 10-05-2022, 05:40 AM by Gintaras.)
Whether QM3 still supports COM component functionality?
QM2 support for COM components is great, and I look forward to making it easy to use COM components in QM3.
Posts: 12,073
Threads: 140
Joined: Dec 2002
Yes. In the Properties dialog click COM or ... and select a COM component. It converts the COM type library to a .NET assembly and you can use it in the script like a type library in QM2.
Posts: 3
Threads: 2
Joined: Mar 2022
Posts: 12,073
Threads: 140
Joined: Dec 2002
03-08-2022, 07:03 AM
(This post was last modified: 03-08-2022, 07:38 AM by Gintaras.)
More info and example.
// script "COM components and type libraries.cs" /// COM component API often are declared in type libraries. In C# they can't be used directly, but the editor can convert a type library to a .NET assembly, and scripts can use the assembly instead. To convert, in Properties click [COM] or [...] and select a type library.
/// Assume you want to use the shell type library in current script.
/// - Open the Properties dialog.
/// - In the "Find in lists" field type <mono>shell<> (optionally, just to make the list smaller).
/// - Click the [COM] button. In the list select "Microsoft Shell Controls and Automation". It converts the COM type library to a .NET assembly.
/// - Click OK. It adds a comment line like /*/ com Shell32 ...; /*/ in the script.
/// - Below the /*/ ... /*/ line press Ctrl+Space and you'll see namespace Shell32 added to the list. Use it like any other namespace.
/*/ com Shell32 1.0 #aab51e65.dll; /*/
using Shell32;
var shell = new Shell32.Shell();
shell.FileRun();
foreach (FolderItem v in shell.NameSpace("C:\\").Items()) {
print.it(v.Path);
}
/// Notes:
/// - To create objects, use interfaces (like <mono>Shell<> in the above example). Not classes like <mono>ShellClass<>.
/// - When converting a COM type library, may print several warnings "can't convert...". Ignore them.
/// - When converting, may create several assembles. The OK button adds them all to the script. One of them is the main; others are its dependencies and usually can be deleted from the script.
/// - In other scripts you can use the same .NET assembly (don't need to convert again). Copy-paste the /*/ com Shell32 ...; /*/. Or convert again, it does not harm.
/// - COM is an old technology. Some downloaded COM components may be 32-bit only. Script processes are 64-bit by default and can't use 32-bit dlls. To use 32-bit dlls, in script Properties select role exeProgram and check bit32.