Jump to content

AU3_WinGetHandle in C# Program


DickWms
 Share

Recommended Posts

I need help using AU3_WinGetHandle in a C# Program. My test program is shown below. It runs as expected with the last two lines commented out. But when the with AU3_WinGetHandle is active I get an error message saying "A problem caused the program to stop working correctly." and the only option is to close the program. I would appreciate if if someone points out my mistake.

Thank you - Dick Williams

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace TryAutoitDLL
{
public partial class Form1 : Form
{
[DllImport("AutoItX3.dll", SetLastError = true, CharSet = CharSet.Auto)]
static public extern int AU3_AutoItSetOption([MarshalAs(UnmanagedType.LPWStr)] string Option, int Value);

[DllImport("AutoItX3.dll", SetLastError = true, CharSet = CharSet.Auto)]
static public extern void AU3_WinActivate([MarshalAs(UnmanagedType.LPWStr)]string Title, [MarshalAs(UnmanagedType.LPWStr)]string Text);

[DllImport("AutoItX3.dll", SetLastError = true, CharSet = CharSet.Auto)]
static public extern void AU3_WinGetHandle([MarshalAs(UnmanagedType.LPWStr)]string Title, [MarshalAs(UnmanagedType.LPWStr)]string Text, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder RetText, int BufSize);

[DllImport("AutoItX3.dll", SetLastError = true, CharSet = CharSet.Auto)]
static public extern int AU3_ControlSend([MarshalAs(UnmanagedType.LPWStr)] string Title, [MarshalAs(UnmanagedType.LPWStr)] string Text, [MarshalAs(UnmanagedType.LPWStr)] string Control, [MarshalAs(UnmanagedType.LPWStr)] string SendText, int Mode);

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
AU3_AutoItSetOption("WinTitleMatchMode", 2);
AU3_WinActivate("Notepad", "");
StringBuilder handle = new StringBuilder();

//AU3_WinGetHandle("Untitled - Notepad", "", handle, 200);
//int i = AU3_ControlSend("", "", handle.ToString(), "aaaa", 0);
}
}
}
Link to comment
Share on other sites

  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...