Phillip007 Posted June 29, 2015 Share Posted June 29, 2015 (edited) Hi, EveryoneI'm just a newbie in AutoIt & hope that will be better with AutoIT in future.I have a problem when using the import DLL AutoIT with C#. The scenario:- 1 Winform with 2 button (button1, button2) & 2 textbox (textbox1, textbox2) --> see "form1.png" below- The my code is very simple:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Runtime.InteropServices;using System.Text;using System.Threading;using System.Windows.Forms;namespace Test_AutoX_without_registerDLL{ public partial class Form1 : Form { [DllImport(@"C:\a\b\AutoItX3_x64.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] public static extern IntPtr AU3_ControlGetText(string p1, string p2, string p3, byte[] RetText, int BufSize); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { AU3_ControlSetText("Form1", "", "[NAME:txttext1]", "ABC", 1); } private void button2_Click(object sender, EventArgs e) { byte[] RetText = new byte[1024]; AU3_ControlGetText("Form1", "", "[NAME:txttext1]", RetText, RetText.Length); txttext2.Text = System.Text.Encoding.ASCII.GetString(RetText); } }} - When I click on button 1, the the textbox1 will show "ABC" --> it was run ok- When I click on button 2, i hope that the textbox 2 will get the text from textbox1 (it's very easy if i use the general code in C#, but in this scenario I just focus to the code AutoIT function)I've tried the code above --> but it's only show only 1 character is "A"I've tried with some similar ways but It doesn't get the expected is "ABC". Hope everyone to help me to solve the problem. Many thanks. Edited June 29, 2015 by Phillip007 Link to comment Share on other sites More sharing options...
JohnOne Posted June 29, 2015 Share Posted June 29, 2015 Well that code will not even run when I try it.Is there some reason you are not using the wrapper included?using System; using System.Windows.Forms; using AutoIt; namespace ControlGetTextCS { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { AutoItX.ControlSetText("Form1", "", "[NAME:textBox1]", "ABC"); } private void button2_Click(object sender, EventArgs e) { string text = AutoItX.ControlGetText("Form1", "", "[NAME:textBox1]"); AutoItX.ControlSetText("Form1", "", "[NAME:textBox2]", text); } } } AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Phillip007 Posted June 30, 2015 Author Share Posted June 30, 2015 (edited) Hi JohnOneIn your way. If we work on any other computers, we should register Autoit on the other computers by installing AutoIT & register AutoIT DLL to registry via regsvr32 for AutoIT DLL.About my approach is create a portable code --> meaning call to AutoIT dll directly --> Not install or register DLL on other computer because we haven't permission fully on that computer for installing or register DLL to registry. So I need call the AutoIT DLL directly via the code below:[DllImport(@"C:\a\b\AutoItX3_x64.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]- I tried the my way it's run ok with some case, such as: click on button 1 --> AutoiT will click on the textbox1 (see the code below)using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Runtime.InteropServices;using System.Text;using System.Threading;using System.Windows.Forms;namespace Test_AutoX_without_registerDLL{ public partial class Form1 : Form { [DllImport(@"C:\\a\\b\AutoItX3_x64.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] public static extern int AU3_ControlClick(string p1, string p2, string p3, string p4, int p5, int p6, int p7); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { AU3_ControlClick("Form1", "", "[NAME:txttext1]", "left", 1, 11, 12); } private void button2_Click(object sender, EventArgs e) {// wait ... } }} ==> But for the getting text it's wasn't correctly --> It was possible to get only 1 character same as the first postedHope the helping.Many thanks, Edited June 30, 2015 by Phillip007 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now