MITH

AU3_PixelSearch

2 posts in this topic

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

#2 ·  Posted (edited)

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

    • vyperhand
      By vyperhand
      I'm struggling to launch a VBS file via autoit using RunWait.  Due to the nature of the deployment tool I am using for said script, I only know that the .vbs files will be in the same directory as my AutoIt-generated .exe, but not what that path will be.  The path will look something like this:
      c:\programdata\vendor\lots\of\folders\randomnumber
      This is generated during deployment and I have no way of predicting the path - therefore, I am not sure how to call back to "same directory" in order to successfully launch the .vbs.
      This line is as close as I have gotten - this fires off the cmd window, but it closes immediately with out information, and the .vbs is not launched.
      RunWait (@ComSpec & " /c" & 'cscript.exe WORKPLEASE.vbs ALL /Q /NoCancel') I thought /c might be the problem, but leaving out the /c element causes me not to even see the momentary CMD window flash by.  Any help will be greatly appreciated, and thanks in advance.
    • PauloRodrigues
      By PauloRodrigues
      I need to select an item from a SAP combobox, could anyone help me or did something like that? I tried to use some AutoIt functions but without success.
      When i try to identify the combobox with au3Info, this is the return:


      Could anyone help me with this challange?
    • ur
      By ur
      I am maintaining all the reusable code in a separate file as library.au3.
      In that file I have referenced some dependent files using fileinstall, so that they will be extracted when necessary.
       
      Problem is, if I use a function in the library.au3 in another script which doesn't require this dependent file, as I am including the whole file using include tag, it is embedding that file also.
      Is there any way to exclude that.
       
    • GTAVLover
      By GTAVLover
      I recently tried to use ControlClick method to send a mouse click command to a button in a application, but I noticed that it is not working when I give first parameter as a window handle (HWND). But, when I give class name or window title, it works fine. I used AutoItX3 and VBScript. 
      Following are the commands I tried in VBScript:
      Dim WINAPI: Set WINAPI = WScript.CreateObject("WinAPIWrapper.WINAPI") Dim AutoItX3: Set AutoItX3 = WScript.CreateObject("AutoItX3.Control") Dim WindowHandle: WindowHandle = WINAPI.WinAPI_FindWindow("my window title", "my window class") 'Window handle obtains fine by my wrapper function 'Above window handle is obtained as a hexadecimal string. (I.E. - 0x00000000) I tried it like: WScript.Echo CStr(AutoItX3.ControlClick(WindowHandle, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(CLng("&h" + Replace(WindowHandle, "0x", "")), "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(000000, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(0x00000000, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK Only following commands work: WScript.Echo CStr(AutoItX3.ControlClick("[CLASS:my window class]", "", "[CLASS:Button; INSTANCE:1]")) // WORKS FINE WScript.Echo CStr(AutoItX3.ControlClick("My window title", "", "[CLASS:Button; INSTANCE:1]")) // WORKS FINE  
      If any of your suggestions don't work, I will have to write a wrapper function myself to send mouse click commands. I chosen AutoIt V3 because it is good specially when comes to send keystrokes to applications. Please tell me why this won't work when I give window handle as first parameter.
      Thanks in advance.