Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
COM error Class not registered
#1
I used ChatGPT to modify the code in the following link.
https://github.com/qgindi/LibreAutomate/...Api_UIA.cs

I attempted to load the assembly using the following two methods:
/*/ com UIAutomationClient 1.0 #b183b9d9.dll; /*/
/*/ nuget -\Interop.UIAutomationClient; /*/

However, after execution, I encountered the same error. The error message is as follows:
System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {30CBE57D-D9D0-452A-AB13-7AC5AC4825EE} failed due to the following error: 80040154 Class not registered (0x80040154 (REGDB_E_CLASSNOTREG)).
   at line 56 in Script7.cs, PowerShellCaretUtil.GetCaretRectInPowerShell(RECT& rect)
   at line 7 in Script7.cs
   >>


I don't quite understand the execution principle of the code, so there might need to be some changes.

Additionally, I am eager to know how to implement this functionality(GetCaretRectInPowerShell) in QM. I am using the following QM code, but I am still unable to achieve the desired functionality.

Thanks in advance for any suggestions and help
David

Function getISECaretPos
Trigger Ax     Help - how to add the trigger to the macro
 
Code:
Copy      Help
typelib UIAutomationClient {944DE083-8FB8-45CF-BCB7-C477ACB2F897} 1.0
UIAutomationClient.CUIAutomation automation
UIAutomationClient.IUIAutomationElement element

if automation.GetFocusedElement(&element)=0
,out 1

ChatGPT Code:
Code:
Copy      Help
// script ""
/*/ com UIAutomationClient 1.0 #b183b9d9.dll; /*/
/*/ nuget -\Interop.UIAutomationClient; /*/

using System;
using System.Runtime.InteropServices;

// Call the method to retrieve the text cursor position
if (PowerShellCaretUtil.GetCaretRectInPowerShell(out var rect))
{

    Console.WriteLine($"Caret Position: Left={rect.Left}, Top={rect.Top}, Right={rect.Right}, Bottom={rect.Bottom}");
}

else
{
    Console.WriteLine("Failed to get caret position.");
}


public static class PowerShellCaretUtil
{
    // Structure for rectangle
    [StructLayout(LayoutKind.Sequential)]
    public struct RECT
    {
        public int Left;
        public int Top;
        public int Right;
        public int Bottom;
    }

    
    // UI Automation COM interface
    [ComImport, Guid("30cbe57d-d9d0-452a-ab13-7ac5ac4825ee")]
    internal class CUIAutomation { }
    
    // UI Automation element interface
    [ComImport, Guid("d22108aa-8ac5-49a5-837b-37bbb3d7591e")]
    [
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    internal interface IUIAutomationElement
    {
        // Method to get the current bounding rectangle of an element
        [PreserveSig] int get_CurrentBoundingRectangle(out RECT retVal);
    }

    
    // UI Automation interface
    [ComImport, Guid("30cbe57d-d9d0-452a-ab13-7ac5ac4825ee")]
    [
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    internal interface IUIAutomation
    {
        // Method to get the focused element
        [PreserveSig] int GetFocusedElement(out IUIAutomationElement element);
    }

    
    // Method to get the text cursor position in PowerShell ISE
    public static bool GetCaretRectInPowerShell(out RECT rect)
    {

        rect = default;
        
        // Create UI Automation instance
        var automation = new CUIAutomation() as IUIAutomation;
        
        // Get the focused UI element
        if (0 == automation.GetFocusedElement(out var element))
        {

            // Get the bounding rectangle of the focused element
            if (0 == element.get_CurrentBoundingRectangle(out rect))
            {

                return true;
            }
        }

        
        return false;
    }
}


Messages In This Thread
COM error Class not registered - by Davider - 02-02-2024, 12:37 AM
RE: COM error Class not registered - by Gintaras - 02-02-2024, 06:35 AM
RE: COM error Class not registered - by Gintaras - 02-02-2024, 07:59 AM
RE: COM error Class not registered - by Davider - 02-02-2024, 08:07 AM
RE: COM error Class not registered - by Gintaras - 02-02-2024, 08:16 AM
RE: COM error Class not registered - by Davider - 02-02-2024, 12:01 PM
RE: COM error Class not registered - by Davider - 02-03-2024, 01:35 AM
RE: COM error Class not registered - by Gintaras - 02-03-2024, 05:50 AM
RE: COM error Class not registered - by Davider - 02-03-2024, 11:13 AM
RE: COM error Class not registered - by Gintaras - 02-03-2024, 12:33 PM
RE: COM error Class not registered - by Davider - 02-03-2024, 09:30 PM
RE: COM error Class not registered - by Gintaras - 02-04-2024, 05:07 AM
RE: COM error Class not registered - by Davider - 02-06-2024, 11:04 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)