|
-
Nov 20th, 2014, 10:18 AM
#1
Thread Starter
New Member
ImageSearchDLL Not working with VB6.0
Hello,
can somebody help me with ImageSearchDLL to make it work ?
Here is my code :
Code:
Private Declare Function ImageSearch Lib "C:\Users\DragosPc\Desktop\sss\ImageSearchDLL.dll" _
(ByVal x1 As Integer, ByVal y1 As Integer, ByVal right As Integer, ByVal bottom As Integer, ByVal findImage As String) As String
Private Sub Command1_Click()
Dim result As String
result = ImageSearch(0, 0, 0, 0, "C:\test.bmp")
Debug.Print result
End Sub
And the Debug.Print returns a strange output:
0 1|%d|%d|%d|%d à?E´ ä³ ä³ e+000 À~PA €ÿÿGAIsProcessorFeaturePresent KERNEL32 1#QNAN 1#INF 1#IND 1#SNAN H P RSDS!›Î1äÉ÷D‡D4Š*/^ c:\imagesearchdll\release\ImageSearchDLL.pdb `D X} ¥ þÿÿÿ Ôÿÿÿ þÿÿÿ Û% ...
i search and found this thread but didn't help me 
http://www.vbforums.com/showthread.p...ht=imagesearch
You can download the dll from here : http://spacefighters.rr.nu/download/ImageSearchDLL.dll
Any ideea ?
Last edited by dimandragos; Nov 20th, 2014 at 11:11 AM.
-
Nov 20th, 2014, 10:57 AM
#2
Re: ImageSearchDLL Not working with VB6.0
You need to remove that DLL from you zip file. If you have a link where someone can download the DLL, then provide that instead. The rules of this forum are that you cannot upload executable files
-
Nov 20th, 2014, 11:12 AM
#3
Thread Starter
New Member
Re: ImageSearchDLL Not working with VB6.0
 Originally Posted by LaVolpe
You need to remove that DLL from you zip file. If you have a link where someone can download the DLL, then provide that instead. The rules of this forum are that you cannot upload executable files
Done, Thanks !
-
Nov 20th, 2014, 11:54 AM
#4
Re: ImageSearchDLL Not working with VB6.0
Do you know if that DLL is using a stdCall or cDecl calling convention. It really matters. If you don't know, you need to try to find out. It appears your return string is corrupted & personally, leaning towards cDecl. From what I can find on the net, the return string should be no more than 50 characters. The source code for that DLL would be helpful
-
Nov 20th, 2014, 12:28 PM
#5
Re: ImageSearchDLL Not working with VB6.0
Here's an idea easy enough to test. Change all 4 Integer types to Long within the function declaration. Unless the DLL is written for 16 bit O/S, likely meant to be Longs.
-
Nov 20th, 2014, 12:30 PM
#6
Re: ImageSearchDLL Not working with VB6.0
Wow LaVolpe, do you think VB6 can make a call that uses the cDecl convention? Gosh, I wouldn't even begin to know how to manually change the stack pointer from within VB6, which would be required upon return of a call using the cDecl convention. I actually Googled just a bit and apparently there are some C "interface" DLLs but wow, what a pita.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Nov 20th, 2014, 12:58 PM
#7
Re: ImageSearchDLL Not working with VB6.0
 Originally Posted by Elroy
Wow LaVolpe, do you think VB6 can make a call that uses the cDecl convention? Gosh, I wouldn't even begin to know how to manually change the stack pointer from within VB6, which would be required upon return of a call using the cDecl convention. I actually Googled just a bit and apparently there are some C "interface" DLLs but wow, what a pita.
Yes, Paul Caton created a thunk and I've used it quite a bit for ZLIB (CDecl) calls. If interested, you can find it on PSC, search for Paul Caton Universal DLL
-
Nov 20th, 2014, 01:30 PM
#8
Re: ImageSearchDLL Not working with VB6.0
You know, PSC has been down for the last day or two. I sure hope that's not a permanent state of affairs.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Nov 20th, 2014, 05:13 PM
#9
Re: ImageSearchDLL Not working with VB6.0
 Originally Posted by LaVolpe
Yes, Paul Caton created a thunk and I've used it quite a bit for ZLIB (CDecl) calls. If interested, you can find it on PSC, search for Paul Caton Universal DLL
The (oleaut32.dll) DispCallFunc-API supports all kinds of different calling-conventions,
__cdecl among them, as well as COM-calls using simple VTable-Offsets, to be able to
work against COM-interfaces which are not easily reachable per VB (having no IDispatch,
or no Typelib available anywhere).
The example below includes a __cdecl-Demo against wsprintf in the C-runtime (msvcrt.dll) -
as well as a Demo, how to implement a simple COM-Interface using this technique (ITaskBarList3).
Here's the Demo: DispInvokeDemo.zip
Olaf
-
Nov 20th, 2014, 07:24 PM
#10
Re: ImageSearchDLL Not working with VB6.0
 Originally Posted by Schmidt
The (oleaut32.dll) DispCallFunc-API supports all kinds of different calling-conventions,
__cdecl among them, as well as COM-calls using simple VTable-Offsets, to be able to
work against COM-interfaces which are not easily reachable per VB (having no IDispatch,
or no Typelib available anywhere).
The example below includes a __cdecl-Demo against wsprintf in the C-runtime (msvcrt.dll) -
as well as a Demo, how to implement a simple COM-Interface using this technique (ITaskBarList3).
Here's the Demo: DispInvokeDemo.zip
Olaf
I'm aware of that & have used it or COM objects. Don't believe the dll in question is ActiveX. FYI: Paul Caton's thunk addressed standard DLLs
-
Nov 20th, 2014, 10:06 PM
#11
Re: ImageSearchDLL Not working with VB6.0
 Originally Posted by LaVolpe
I'm aware of that & have used it or COM objects.
Don't believe the dll in question is ActiveX.
FYI: Paul Caton's thunk addressed standard DLLs
You missed my point entirely (perhaps didn't even looked at the demo),
since it demonstrated calls against msvcrt.dll, which *is* a __cdecl-exporting Standard-Dll...
So the DispCallFunc-API supports not only Calls per VTable-Pointer-offsets into COM-Instances,
but also Func-Pointer-Calls against "Flat-Dlls" (__stdcall convention as well as __cdecl convention).
Olaf
-
Nov 20th, 2014, 10:43 PM
#12
Re: ImageSearchDLL Not working with VB6.0
That's pretty cool. Where did you find the documentation on that function? When I last researched that API, everything I found indicated it was intended/used only for IDispatch::Invoke.
Had no idea you could pass the function pointer as the VTable parameter along with a null pUnk and it would happily call the function.
FYI: For another sample usage of that API with call made to a VB object (drag/drop DataObject), this posting shows one way of extracting dropped files from a Windows compressed folder
Last edited by LaVolpe; Nov 21st, 2014 at 08:16 AM.
-
Nov 21st, 2014, 07:33 AM
#13
Thread Starter
New Member
Re: ImageSearchDLL Not working with VB6.0
Vb .Net
Code:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("ImageSearchDLL.dll", EntryPoint:="ImageSearch")> _
Public Shared Function ImageSearch(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal str As String) As String
End Function
Public Shared Function FindImage(ByVal bmp As String) As Integer()
Dim x1 As Integer
Dim y1 As Integer
Dim Array1 As Integer() = New Integer(2) {}
Dim strRes As String = ImageSearch(x1, y1, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, bmp)
If strRes = "0" Then
Array1(0) = 0
Return Array1
Else
Dim co As String() = strRes.Split("|"c)
Array1(0) = Integer.Parse(co(1))
Array1(1) = Integer.Parse(co(2))
Return Array1
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Res() As Integer = FindImage("C:\test.bmp")
If Res(0) > 0 And Res(1) > 0 Then
MessageBox.Show("The position of the image is :" & vbNewLine & _
"Width: " & Res(0).ToString() & vbNewLine & _
"Height: " & Res(1).ToString())
Else
MessageBox.Show("Can't find image on screen !")
End If
End Sub
End Class
Back, i think i will finish my project in Vb .Net but if somebody can fix that code(vb6) i will be grateful.
Thank you for all your help.
LaVolpe, i like your projects on psc
Last edited by dimandragos; Nov 21st, 2014 at 07:39 AM.
-
Nov 21st, 2014, 11:58 AM
#14
Re: ImageSearchDLL Not working with VB6.0
 Originally Posted by LaVolpe
Where did you find the documentation on that function? When I last researched that API, everything I found indicated it was intended/used only for IDispatch::Invoke.
Had no idea you could pass the function pointer as the VTable parameter along with a null pUnk and it would happily call the function.
You're right, the MSDN-documentation doesn't point out this behaviour or "mode" -
not sure where I read this first (a few years ago) - I think it was in a german forum...
Olaf
-
Nov 24th, 2014, 05:21 AM
#15
Re: ImageSearchDLL Not working with VB6.0
 Originally Posted by Schmidt
... not sure where I read this first (a few years ago) - I think it was in a german forum...

 Originally Posted by Schmidt
@Zvoni
The DispCallFunc is basically the "generic and official Function-Caller by pointer", every VB-Dev was
always looking for (often resorting to CallWindowProc- or ASM-Hacks instead) - not sure who needs
to be given the credits for the first working VB-example (wasn't me, found it not that long ago
in a german forum the first time)... googling - ... - well, seems that the first "working VB-example"
is from 2003: http://www.activevb.de/tipps/vb6tipps/tipp0600.html
I was using Paul Catons stuff before - but since there was this nice explicit Parameter CC_STDCALL
I googled a bit more and found a whole Enum-List:
Public Enum CallingConventions
CC_FASTCALL
CC_CDECL
CC_PASCAL
CC_MACPASCAL
CC_STDCALL
CC_RESERVED
CC_SYSCALL
CC_MPWCDECL
CC_MPWPASCAL
End Enum
More googling and experimenting revealed, that the Function-Pointer is internally resolved by:
dereferencedResultOfParam_ppv + Vtbl_Offset
And (luckily) passing a Null to ppV - and the direct Function-Pointer in the Vtbl-Offset-Param,
one can do also all kind of "normal API-Calls" (not only Disp- or COM-Calls).
And in this "direct FuncPtr-Mode", the above Enum comes in very handy - and is working as
expected.
Here's a small Demo, which shows all 3 "Modes", in which DispCallFunc can be used now with
VB (StdCall-, CDECL- calls and of course also COM- (VTbl-) Calls.
http://www.vbRichClient.com/Download...InvokeDemo.zip
Olaf
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Nov 24th, 2014, 01:39 PM
#16
Re: ImageSearchDLL Not working with VB6.0
Thanks Bonnie, for digging that out.
(was aware that I've posted the info somewhere recently, but not that it was here in this Forum) ...
The blessings of getting old(er) perhaps. 
Olaf
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|