Jump to content
MITH

AU3_PixelSearch

Recommended Posts

MITH

I am trying to use pixel search using VBA but it is returning Bad DLL calling convention error. I don't know where this is going wrong

Hoping that you may be able to help.

Here's my code:

Public Function PixelSearch(lX1 As Long, lY1 As Long, lX2 As Long, lY2 As Long, lColor As Long, Optional lVariations As Long = 0, Optional lStep As Long = 1) As String
Dim Rect As LPRECT, szResult As String, pos As Integer
'szResult = String(255, vbNullChar)

Rect.X = lX1
Rect.Y = lY1
Rect.Width = lX2
Rect.Height = lY2
'Private Declare Sub AU3_PixelSearch Lib "AutoItX3.dll" (ByRef LRECT As LPRECT, ByVal nColor As Long, ByVal nVariations As Long, ByVal nStep As Long, ByVal szResult As LongPtr, ByVal nBufSize As Long)

AU3_PixelSearch Rect, lColor, lVariations, lStep, StrPtr(szResult), Len(szResult)
   If pos > 0 Then
    szResult = Left(szResult, pos - 1)
   End If
PixelSearch = Trim(szResult)
End Function

 

Share this post


Link to post
Share on other sites
MITH
On 6/9/2016 at 6:33 PM, MITH said:

I am trying to use pixel search using VBA but it is returning Bad DLL calling convention error. I don't know where this is going wrong

Hoping that you may be able to help.

Here's my code:


Public Function PixelSearch(lX1 As Long, lY1 As Long, lX2 As Long, lY2 As Long, lColor As Long, Optional lVariations As Long = 0, Optional lStep As Long = 1) As String
Dim Rect As LPRECT, szResult As String, pos As Integer
'szResult = String(255, vbNullChar)

Rect.X = lX1
Rect.Y = lY1
Rect.Width = lX2
Rect.Height = lY2
'Private Declare Sub AU3_PixelSearch Lib "AutoItX3.dll" (ByRef LRECT As LPRECT, ByVal nColor As Long, ByVal nVariations As Long, ByVal nStep As Long, ByVal szResult As LongPtr, ByVal nBufSize As Long)

AU3_PixelSearch Rect, lColor, lVariations, lStep, StrPtr(szResult), Len(szResult)
   If pos > 0 Then
    szResult = Left(szResult, pos - 1)
   End If
PixelSearch = Trim(szResult)
End Function

 

I got the function to work but it returns zero :(.

Need some expert advice on how to make this work.

Private Declare Function AU3_PixelGetColor Lib "AutoItX3.dll" (ByVal nX As Long, ByVal nY As Long) As Integer
Private Declare Sub AU3_PixelSearch Lib "AutoItX3.dll" (ByRef lpRect As lpRect, ByVal nCol As Integer, ByVal nVar As Integer, ByVal nStep As Integer, ByRef pPointResult As lpPoint)

Public Function PixelGetColor(lX1 As Long, lY1 As Long) As Integer
PixelGetColor = AU3_PixelGetColor(lX1, lY1)
End Function

Public Function PixelSearch(lX1 As Long, lY1 As Long, lX2 As Long, lY2 As Long, lColor As Integer, Optional lVariations As Integer = 0, Optional lStep As Integer = 1) As lpPoint
Dim Rect As lpRect, lpresult As lpPoint
Dim strValue
strValue = Space(255)

Rect.X = lX1
Rect.Y = lY1
Rect.Width = lX2
Rect.Height = lY2

AU3_PixelSearch Rect, lColor, lVariations, lStep, lpresult

PixelSearch = lpresult
End Function

 

Edited by MITH
Line which could cause confusion

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

  • Similar Content

    • PramodR
      By PramodR
       
      I see couple of ways to import module ,  one with specifying absolute path of the file to get imported, by this logic i believe to import a specific module will be like #include <c:\modulepath\duplicatemodule.au3>
      but i see some registry changes also made in this link , can someone explain why that registry change is really required.
       
    • PramodR
      By PramodR
       
      I am trying to execute a exe file in auto it as elevated previlage , but not successful till now . below are the methods i tried till now.
      Disabled UAC access from windows and  selected run only as administrator from executable properties.  i logged in as administrator but still exe needs to launch as run as administrator.
       
      Used Below methods from forum still no luck. anything i missing? i tried to use powershell.ps1 intead of exe as well.
      1.  Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, $RUN_LOGON_NOPROFILE, "c:\Exec.exe", "", @SW_SHOWMAXIMIZED)
      2.  RunWait("C:\Automation\TestScripts\Writefilter.exe", @WindowsDir, @SW_MAXIMIZE)     - Std out error
       
      This command gives out put as running with admin rights
      #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #RequireAdmin Example() Func Example()     ; Change the username and password to the appropriate values for your system.     Local $sUserName = "Admin"     Local $sPassword = "PASSWORD"     Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 0, "noetpad.exe", "", @SW_SHOWMAXIMIZED)     ; Run Notepad with the window maximized. Notepad is run under the user previously specified. ;~     RunWait(@WindowsDir & "C:\automation\TestScripts\Writefilter.exe", @WindowsDir, @SW_MAXIMIZE) EndFunc   
    • PramodR
      By PramodR
      Hello,
      I have below code which execute well when all prerequisite met, when window pop up is not available its throwing an error. i want to capture error instead of error  out.
      error handling added in the code to capture it but it does not work still giving me error saying Variable must be of type "Object".
      $oCurWin.FindAll($treescope_subtree, $oCondition, $pElements)
      $oCurWin^ ERROR
      How to catch error properly . 
       
       
    • PramodR
      By PramodR
      Hello,
      I have to execute below block of code in elevated previllage, as that particular wmic class will work only with admin previlage.
      i am getting out put when i launch autoit as administrator,  but i will not be able to launch autoit as admin in this particular case but my user have admin rights.
      is there any better way i can run those command as administrator.?
      tried below steps:
      i have tried #RequireAdmin but that creates a user prompt  Tried using Runas command but gives error as wrong username or password , stuck with that step.  
       
    • IgImAx
      By IgImAx
      Hi
       
      UPDATED Notes: ===============================================================================
      UPDATED: My main and second questions answered. Here the answers:
      To add/access WinMenuSelectItem you need to [Thanks to Fernando_Marinho]: Add AutoItX.Dotnet in Manage NuGet Packages Right Click in your Project -> Add -> Reference... -> COM ( Type Libraries )than, check the option AutoItX3 1.0 Type Library  using AutoItX3Lib; AutoItX3 au3 = new AutoItX3(); au3.WinMenuSelectItem("", ...) My full source code in C# exists in 11 posts in below. How to access those overloaded methods in AutoitX3 that are not accessible via above method!? Or how to fix AutoitX3 DLL Registration need in target computers without Autoit pre-installed on them!? Please check my post at 14 posts below!
      =============================================================================== Original Post:
       
       
      I was writing a small app in Autoit to close µTorrent app. It was working. Then I try to import AutoItX into C#, but unfortunately this method
      WinMenuSelectItem Couldn't find by IntelliSense and If I typed completely it still give me this message:
      Please check the image. I Google it and I found this QA at stackoverflow: Autoit error within C# application I saw they use this line:
      au = new AutoItX3Lib.AutoItX3Class(); I figure it how to add 'AutoItX3Lib' to project (by adding 'AutoItX3.dll' to reference) but again! When I use this line:
      var au = new AutoItX3Class(); I got this error message: Interop type 'AutoItX3Class' cannot be embedded. Use the applicable interface instead.
      My system info:
      Visual Studio 2017 Enterprise - v15.5.4
      X64 Windows 10 Enterprise 1607
      Thanks in advanced
      IgImAx

×