Sign in to follow this  
Followers 0
EKey

ControlGetText problem

5 posts in this topic

Hello,

I imported AutoItX.dll and most of subs and functions work, but calling the ControlGetText function gives a problem. I modify the importing function this way and that way, but it doesn't work for me.

Public Class AIt
    <DllImport("AutoItX3.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Public Shared Function AU3_ControlGetText(<MarshalAs(UnmanagedType.LPWStr)> ByVal Title As String, _
                                              <MarshalAs(UnmanagedType.LPWStr)> ByVal Text As String, _
                                              <MarshalAs(UnmanagedType.LPWStr)> ByVal Control As String, _
                                              Optional ByVal ControlText As Byte = 0, Optional ByVal BufSize As Integer = 0) As String
    End Function
end class

'calling the function:
 AIt.AU3_ControlSetText("", "", Ctrl, Value)

Could you please advise where is the problem in code

Share this post


Link to post
Share on other sites



void AU3_ControlGetText(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl, LPWSTR szControlText, int nBufSize);

This is the C++ version. You can't go changing around the return type and mistreating the parameters.

Use this for VB.Net.

Declare Unicode Sub AU3_ControlGetText Lib "AutoItX3.dll" (ByVal szTitle As String, ByVal szText As String, ByVal szControl As String, ByRef szControlText() As Char, ByVal nBufSize As Integer)

Call it like

Dim buffer(1024) As Char
AU3_ControlGetText("Some Window", "", "Control ID", buffer, 1024)

Share this post


Link to post
Share on other sites

Thank you, Richard. It works!!!

Share this post


Link to post
Share on other sites

Good to know. I don't use VB.Net and was a little unsure on array declarations.

Share this post


Link to post
Share on other sites

Good to know. I don't use VB.Net and was a little unsure on array declarations.

Finally I used the definition:

<DllImport("AutoItX3.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Public Shared Sub AU3_ControlGetText(<MarshalAs(UnmanagedType.LPWStr)> ByVal Title As String, _
                                              <MarshalAs(UnmanagedType.LPWStr)> ByVal Text As String, _
                                              <MarshalAs(UnmanagedType.LPWStr)> ByVal Control As String, _
                                              ByVal ControlText() As Byte, _
                                              Optional ByVal BufSize As Integer = 1024)
    End Sub

Although the code is quite different but your idea, Richard, was very useful. Thank you again.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0