Jump to content

AU3_PixelSearch


MITH
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

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
Link to comment
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
 Share

×
×
  • Create New...