Schaffe es nicht C++ DLL unter .Net zunutzen :(

  • VB.NET

Es gibt 18 Antworten in diesem Thema. Der letzte Beitrag () ist von RodFromGermany.

    Schaffe es nicht C++ DLL unter .Net zunutzen :(

    Hallo,

    Ich versuche jetzt schon länger die ImageSearchDLL.dll in .Net zunutzen aber leider scheitere ich.

    autohotkey.com/docs/commands/ImageSearch.htm

    Mein Code:

    VB.NET-Quellcode

    1. Public Declare Function ImageSearch Lib "ImageSearchDLL.dll" (ByVal OutputVarX As Integer, ByVal OutputVarY As Integer, ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer, ByVal ImageFile As String) As String


    Ne Exception taucht leider nicht auf nur steht im "Direktfenster" immer:

    Quellcode

    1. Eine Ausnahme (erste Chance) des Typs "System.AccessViolationException" ist in WindowsApplication1.exe aufgetreten.


    Hoffe jemand kann mir Helfen :I

    MFG.

    vbler.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „vbler“ ()

    Du kannst keinen .NET-String so an eine C++-DLL übergeben.
    Da fehlt so was wie <MarshalAs(UnmanagedType.LPStr)> .

    VB.NET-Quellcode

    1. Imports System.Runtime.InteropServices
    2. Public Class Form1
    3. <DllImport("ImageSearchDLL.dll")> _
    4. Friend Shared Function ImageSearch(ByVal OutputVarX As Integer, ByVal OutputVarY As Integer, ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer, <MarshalAs(UnmanagedType.LPStr)> ImageFile As String) _
    5. As <MarshalAs(UnmanagedType.LPStr)> String
    6. End Function
    7. '...
    8. End Class
    Ob das UnmanagedType.LPStr das richtige ist, weiß ich nicht, da ich die C++-Deklaration der Funktion nicht kenne.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    mhh ich habe es jetzt mit einen Code ausdem Internet geschafft... aber leider damit es funktioniert muss ich immer den Fensternamen angeben aber will ich ja nicht weil ich das Image ja finden möchte egal im welchen fenster das ist.

    VB.NET-Quellcode

    1. Dim a As New AutoItX3Lib.AutoItX3
    2. Dim Bild2 = Bild
    3. Dim toleranz As Integer = 0
    4. If Not IO.File.Exists(Bild) Then
    5. MessageBox.Show("Die Datei " & Bild2 & "konnte nicht gefunden werden. Das Programm wird beendet.")
    6. End
    7. End If
    8. If toleranz > 0 Then Bild = "*" & toleranz & " " & Bild
    9. Dim x As String = ImageSearch(a.WinGetCaretPosX(), a.WinGetCaretPosY(), a.WinGetCaretPosX() + a.WinGetClientSizeWidth(FensterName), a.WinGetCaretPosY() + a.WinGetClientSizeHeight(FensterName), Bild)
    10. If x = "0" Then
    11. MessageBox.Show("Das Bild " & Bild2 & " konnte nicht auf dem Bildschirm gefunden werden. Das Programm wird beendet.")
    12. End
    13. Else
    14. Dim y = x.Split("|")
    15. If Mitte = True Then
    16. Return Point.Subtract(New Point(y(1), y(2)), New Size(y(3) \ -2, y(4) \ -2))
    17. Else
    18. Return New Point(y(1), y(2))
    19. End If
    20. End If
    21. End Function
    Gib Deinem Programm mal Option Strict On.
    Hast Du Dein Programm mit x86 kompiliert??
    Kannst Du die DLL mal dranhängen (als zip)?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    1.)

    VB.NET-Quellcode

    1. <DllImport("ImageSearchDLL.dll")> Public Function ImageSearch(ByVal x1 As Integer, ByVal y1 As Integer, ByVal right As Integer, ByVal bottom As Integer, ByVal findImage As String) As String
    2. End Function
    3. Function ImageSearch(ByVal Bild As String, ByVal FensterName As String, Optional ByVal Mitte As Boolean = True) As Point
    4. Dim a As New AutoItX3Lib.AutoItX3
    5. Dim Bild2 = Bild
    6. Dim toleranz As Integer = 0
    7. If Not IO.File.Exists(Bild) Then
    8. MessageBox.Show("Die Datei " & Bild2 & "konnte nicht gefunden werden. Das Programm wird beendet.")
    9. End
    10. End If
    11. If toleranz > 0 Then Bild = "*" & toleranz & " " & Bild
    12. Dim x As String = ImageSearch(a.WinGetCaretPosX(), a.WinGetCaretPosY(), a.WinGetCaretPosX() + a.WinGetClientSizeWidth(FensterName), a.WinGetCaretPosY() + a.WinGetClientSizeHeight(FensterName), Bild)
    13. If x = "0" Then
    14. MessageBox.Show("Das Bild " & Bild2 & " konnte nicht auf dem Bildschirm gefunden werden. Das Programm wird beendet.")
    15. End
    16. Else
    17. Dim y = x.Split(CChar("|"))
    18. If Mitte = True Then
    19. Return Point.Subtract(New Point(CInt(y(1)), CInt(y(2))), New Size(CInt(CLng(y(3)) \ -2), CInt(CLng(y(4)) \ -2)))
    20. Else
    21. Return New Point(CInt(y(1)), CInt(y(2)))
    22. End If
    23. End If
    24. End Function


    2.)CPU Any?!

    3.)ImageSearchDLL.zip

    vbler schrieb:

    VB.NET-Quellcode

    1. <DllImport("ImageSearchDLL.dll")> _
    2. Public Function ImageSearch(ByVal x1 As Integer, ByVal y1 As Integer, ByVal right As Integer, ByVal bottom As Integer, ByVal findImage As String) As String
    3. End Function
    Diese Deklaration ist falsch.
    Leider habe ich keine richtige gefunden, probieren hat auch nichts geholfen.
    Versuch mal, die richtige Deklaration aufzutreiben, wenn Du sie hast, melde Dich wieder. :S
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Bin mir jetzt zwar nicht zu 100% sicher aber sollten die ersten beiden Variablen nicht als ByRef declariert werden?
    The names of the variables in which to store the X and Y coordinates of the upper-left pixel of where the image was found on the screen (if no match is found, the variables are made blank). Coordinates are relative to the active window unless CoordMode was used to change that.

    Either or both of these parameters may be left blank, in which case ErrorLevel (see below) can be used to determine whether a match was found.

    Wulf schrieb:

    sollten die ersten beiden Variablen nicht als ByRef declariert werden?
    Auch das habe ich probiert, aber es reicht nicht.
    Ich hab auch diese beiden als IntPtr probiert, geht auch nicht.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    mhh, da die ImageSearchDLL oft in AutoIT genutzt wird habe ich nur einen AutoIT Code womit man die ImageSearchDLL in AutoIT nutzen kann.

    Brainfuck-Quellcode

    1. #include-once
    2. ; ------------------------------------------------------------------------------
    3. ;
    4. ; AutoIt Version: 3.0
    5. ; Language: English
    6. ; Description: Functions that assist with Image Search
    7. ; Require that the ImageSearchDLL.dll be loadable
    8. ;
    9. ; ------------------------------------------------------------------------------
    10. ;===============================================================================
    11. ;
    12. ; Description: Find the position of an image on the desktop
    13. ; Syntax: _ImageSearchArea, _ImageSearch
    14. ; Parameter(s):
    15. ; $findImage - the image to locate on the desktop
    16. ; $tolerance - 0 for no tolerance (0-255). Needed when colors of
    17. ; image differ from desktop. e.g GIF
    18. ; $resultPosition - Set where the returned x,y location of the image is.
    19. ; 1 for centre of image, 0 for top left of image
    20. ; $x $y - Return the x and y location of the image
    21. ;
    22. ; Return Value(s): On Success - Returns 1
    23. ; On Failure - Returns 0
    24. ;
    25. ; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
    26. ; a desktop region to search
    27. ;
    28. ;===============================================================================
    29. Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
    30. return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance)
    31. EndFunc
    32. Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)
    33. ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
    34. if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
    35. $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
    36. ; If error exit
    37. if $result[0]="0" then return 0
    38. ; Otherwise get the x,y location of the match and the size of the image to
    39. ; compute the centre of search
    40. $array = StringSplit($result[0],"|")
    41. $x=Int(Number($array[2]))
    42. $y=Int(Number($array[3]))
    43. if $resultPosition=1 then
    44. $x=$x + Int(Number($array[4])/2)
    45. $y=$y + Int(Number($array[5])/2)
    46. endif
    47. return 1
    48. EndFunc
    49. ;===============================================================================
    50. ;
    51. ; Description: Wait for a specified number of seconds for an image to appear
    52. ;
    53. ; Syntax: _WaitForImageSearch, _WaitForImagesSearch
    54. ; Parameter(s):
    55. ; $waitSecs - seconds to try and find the image
    56. ; $findImage - the image to locate on the desktop
    57. ; $tolerance - 0 for no tolerance (0-255). Needed when colors of
    58. ; image differ from desktop. e.g GIF
    59. ; $resultPosition - Set where the returned x,y location of the image is.
    60. ; 1 for centre of image, 0 for top left of image
    61. ; $x $y - Return the x and y location of the image
    62. ;
    63. ; Return Value(s): On Success - Returns 1
    64. ; On Failure - Returns 0
    65. ;
    66. ;
    67. ;===============================================================================
    68. Func _WaitForImageSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance)
    69. $waitSecs = $waitSecs * 1000
    70. $startTime=TimerInit()
    71. While TimerDiff($startTime) < $waitSecs
    72. sleep(100)
    73. $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance)
    74. if $result > 0 Then
    75. return 1
    76. EndIf
    77. WEnd
    78. return 0
    79. EndFunc
    80. ;===============================================================================
    81. ;
    82. ; Description: Wait for a specified number of seconds for any of a set of
    83. ; images to appear
    84. ;
    85. ; Syntax: _WaitForImagesSearch
    86. ; Parameter(s):
    87. ; $waitSecs - seconds to try and find the image
    88. ; $findImage - the ARRAY of images to locate on the desktop
    89. ; - ARRAY[0] is set to the number of images to loop through
    90. ; ARRAY[1] is the first image
    91. ; $tolerance - 0 for no tolerance (0-255). Needed when colors of
    92. ; image differ from desktop. e.g GIF
    93. ; $resultPosition - Set where the returned x,y location of the image is.
    94. ; 1 for centre of image, 0 for top left of image
    95. ; $x $y - Return the x and y location of the image
    96. ;
    97. ; Return Value(s): On Success - Returns the index of the successful find
    98. ; On Failure - Returns 0
    99. ;
    100. ;
    101. ;===============================================================================
    102. Func _WaitForImagesSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance)
    103. $waitSecs = $waitSecs * 1000
    104. $startTime=TimerInit()
    105. While TimerDiff($startTime) < $waitSecs
    106. for $i = 1 to $findImage[0]
    107. sleep(100)
    108. $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance)
    109. if $result > 0 Then
    110. return $i
    111. EndIf
    112. Next
    113. WEnd
    114. return 0
    115. EndFunc


    villeicht hilft das ja weiter...

    vbler schrieb:

    Quellcode

    1. $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
    Diese Zeile ist interessant.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!

    VB.NET-Quellcode

    1. <DllImport("ImageSearchDLL.dll")> Public Shared Function ImageSearch(ByRef x1 As Integer, ByRef y1 As Integer, ByVal right As Integer, ByVal bottom As Integer, ByVal findimage$) As String
    2. End Function



    So Funktionierts nicht wenn ich richtig gemacht habe..

    RodFromGermany schrieb:

    Du kannst keinen .NET-String so an eine C++-DLL übergeben.
    Da fehlt so was wie <MarshalAs(UnmanagedType.LPStr)> .
    Das hatten wir ja bereits ...
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Da müsstest Du vielleicht noch mal mit Frau Google reden. :S
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Weil Strings in einzelnen Programmiersprachen völlig unterschiedlich im Speicher abgelegt sind und entsprechend konvertiert werden müssen.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    habe jezt gegoogelt vllt hilfts es

    c-plusplus.de/forum/268793-full
    cplusplus.com/forum/beginner/26385/



    Ich glaube das hier kann helfen :


    pastebin.com/2WjBnnNk


    bzw dieser Code:

    VB.NET-Quellcode

    1. [ public static class IMGSearch
    2. {
    3. //[DllImport("ImageSearchDLL.dll", EntryPoint="ImageSearch")]
    4. [DllImport("Boxy")]
    5. public static extern string ImageSearch(int x1, int y1, int x2, int y2, string str);
    6. /// <summary>
    7. /// The main entry point for the application.
    8. /// </summary>
    9. [STAThread]
    10. static void Main2()
    11. {
    12. Application.EnableVisualStyles();
    13. Application.SetCompatibleTextRenderingDefault(false);
    14. Application.Run(new Form1());
    15. }
    16. public static int[] FindImage(int L, int T, int R, int B, string F)
    17. {
    18. int[] aRTN = new int[5];
    19. //MessageBox.Show(R.ToString());
    20. string rtn = ImageSearch(L, T, R, B, F);
    21. //MessageBox.Show(rtn);
    22. if (rtn == "0")
    23. {
    24. aRTN[0] = 0;
    25. return aRTN;
    26. }
    27. else
    28. {
    29. string[] coords = rtn.Split('|'); //split return value of imagesearch into array
    30. //int[] aRTN = new int[5]; //declare int array with enough elements
    31. aRTN[0] = int.Parse(coords[0]); //convert the string values into ints
    32. aRTN[1] = int.Parse(coords[1]);
    33. aRTN[2] = int.Parse(coords[2]);
    34. aRTN[3] = int.Parse(coords[3]);
    35. aRTN[4] = int.Parse(coords[4]);
    36. return aRTN;
    37. }
    38. }
    39. }



    Edit:

    Kommische Sache:

    Mein Code:

    Imports System.Runtime.InteropServices
    Imports System
    Public Class Form1

    VB.NET-Quellcode

    1. <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
    2. End Function
    3. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4. Dim x1 As Integer
    5. Dim y1 As Integer
    6. Dim result As Integer = ImageSearch(x1, y1, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, "C:\a.png")
    7. MsgBox(result)
    8. End Sub
    9. End Class


    Wenn das Image nicht gefunden wird kommt eine Messagebox wo 0 steht. Aber wenn das Image Gefunden wird... kommt ne Exception versteh ich nicht aber ist doch schonmal etwas xD


    VB.NET-Quellcode

    1. Informationen über das Aufrufen von JIT-Debuggen
    2. anstelle dieses Dialogfelds finden Sie am Ende dieser Meldung.
    3. ************** Ausnahmetext **************
    4. System.InvalidCastException: Ungültige Konvertierung von der Zeichenfolge 1|248|164|47|38 in Typ Integer. ---> System.FormatException: Die Eingabezeichenfolge hat das falsche Format.
    5. bei Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)
    6. bei Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
    7. --- Ende der internen Ausnahmestapelüberwachung ---
    8. bei Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
    9. bei ImageSearchDLL.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\Wohnzimmer\documents\visual studio 2010\Projects\ImageSearchDLL\ImageSearchDLL\Form1.vb:Zeile 10.
    10. bei System.EventHandler.Invoke(Object sender, EventArgs e)
    11. bei System.Windows.Forms.Form.OnLoad(EventArgs e)
    12. bei System.Windows.Forms.Form.OnCreateControl()
    13. bei System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
    14. bei System.Windows.Forms.Control.CreateControl()
    15. bei System.Windows.Forms.Control.WmShowWindow(Message& m)
    16. bei System.Windows.Forms.Control.WndProc(Message& m)
    17. bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    18. bei System.Windows.Forms.ContainerControl.WndProc(Message& m)
    19. bei System.Windows.Forms.Form.WmShowWindow(Message& m)
    20. bei System.Windows.Forms.Form.WndProc(Message& m)
    21. bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    22. bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    23. bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    24. ************** Geladene Assemblys **************
    25. mscorlib
    26. Assembly-Version: 4.0.0.0.
    27. Win32-Version: 4.0.30319.17626 built by: FX45RCREL.
    28. CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll.
    29. ----------------------------------------
    30. ImageSearchDLL
    31. Assembly-Version: 1.0.0.0.
    32. Win32-Version: 1.0.0.0.
    33. CodeBase: file:///C:/Users/Wohnzimmer/Documents/Visual%20Studio%202010/Projects/ImageSearchDLL/ImageSearchDLL/bin/Debug/ImageSearchDLL.exe.
    34. ----------------------------------------
    35. Microsoft.VisualBasic
    36. Assembly-Version: 10.0.0.0.
    37. Win32-Version: 11.0.50501.17626 built by: FX45RCREL.
    38. CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll.
    39. ----------------------------------------
    40. System
    41. Assembly-Version: 4.0.0.0.
    42. Win32-Version: 4.0.30319.17626 built by: FX45RCREL.
    43. CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll.
    44. ----------------------------------------
    45. System.Core
    46. Assembly-Version: 4.0.0.0.
    47. Win32-Version: 4.0.30319.17626 built by: FX45RCREL.
    48. CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll.
    49. ----------------------------------------
    50. System.Windows.Forms
    51. Assembly-Version: 4.0.0.0.
    52. Win32-Version: 4.0.30319.17626 built by: FX45RCREL.
    53. CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll.
    54. ----------------------------------------
    55. System.Drawing
    56. Assembly-Version: 4.0.0.0.
    57. Win32-Version: 4.0.30319.17626 built by: FX45RCREL.
    58. CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll.
    59. ----------------------------------------
    60. System.Configuration
    61. Assembly-Version: 4.0.0.0.
    62. Win32-Version: 4.0.30319.17626 built by: FX45RCREL.
    63. CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll.
    64. ----------------------------------------
    65. System.Xml
    66. Assembly-Version: 4.0.0.0.
    67. Win32-Version: 4.0.30319.17626 built by: FX45RCREL.
    68. CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll.
    69. ----------------------------------------
    70. System.Runtime.Remoting
    71. Assembly-Version: 4.0.0.0.
    72. Win32-Version: 4.0.30319.17626 built by: FX45RCREL.
    73. CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll.
    74. ----------------------------------------
    75. mscorlib.resources
    76. Assembly-Version: 4.0.0.0.
    77. Win32-Version: 4.0.30319.17626 built by: FX45RCREL.
    78. CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_de_b77a5c561934e089/mscorlib.resources.dll.
    79. ----------------------------------------
    80. Microsoft.VisualBasic.resources
    81. Assembly-Version: 10.0.0.0.
    82. Win32-Version: 11.0.50501.17626 built by: FX45RCREL.
    83. CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic.resources/v4.0_10.0.0.0_de_b03f5f7f11d50a3a/Microsoft.VisualBasic.resources.dll.
    84. ----------------------------------------
    85. System.Windows.Forms.resources
    86. Assembly-Version: 4.0.0.0.
    87. Win32-Version: 4.0.30319.17626 built by: FX45RCREL.
    88. CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_de_b77a5c561934e089/System.Windows.Forms.resources.dll.
    89. ----------------------------------------
    90. ************** JIT-Debuggen **************
    91. Um das JIT-Debuggen (Just-In-Time) zu aktivieren, muss in der
    92. Konfigurationsdatei der Anwendung oder des Computers
    93. (machine.config) der jitDebugging-Wert im Abschnitt system.windows.forms festgelegt werden.
    94. Die Anwendung muss mit aktiviertem Debuggen kompiliert werden.
    95. Zum Beispiel:
    96. <configuration>
    97. <system.windows.forms jitDebugging="true" />
    98. </configuration>
    99. Wenn das JIT-Debuggen aktiviert ist, werden alle nicht behandelten
    100. Ausnahmen an den JIT-Debugger gesendet, der auf dem
    101. Computer registriert ist, und nicht in diesem Dialogfeld behandelt.

    Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von „vbler“ ()

    Ich habe es erlich geschafft :O

    Hier der Code die AutoITLib ist nur drin um auf dir Koordis zu drücken...

    Danke an Alle :)


    VB.NET-Quellcode

    1. Imports System.Runtime.InteropServices
    2. Imports System
    3. Imports AutoItX3Lib
    4. Public Class Form1
    5. <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
    6. End Function
    7. Public Shared Function FindImage(ByVal L As Integer, ByVal T As Integer, ByVal R As Integer, ByVal B As Integer, ByVal F As String) As Integer()
    8. Dim aRTN As Integer() = New Integer(4) {}
    9. 'MessageBox.Show(R.ToString());
    10. Dim rtn As String = ImageSearch(L, T, R, B, F)
    11. ' MessageBox.Show(rtn)
    12. If rtn = "0" Then
    13. aRTN(0) = 0
    14. Return aRTN
    15. Else
    16. Dim coords As String() = rtn.Split("|"c)
    17. 'split return value of imagesearch into array
    18. 'int[] aRTN = new int[5]; //declare int array with enough elements
    19. aRTN(0) = Integer.Parse(coords(0))
    20. 'convert the string values into ints
    21. aRTN(1) = Integer.Parse(coords(1))
    22. aRTN(2) = Integer.Parse(coords(2))
    23. aRTN(3) = Integer.Parse(coords(3))
    24. aRTN(4) = Integer.Parse(coords(4))
    25. Return aRTN
    26. End If
    27. End Function
    28. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    29. Dim x1 As Integer
    30. Dim y1 As Integer
    31. Dim res() As Integer = FindImage(x1, y1, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, "C:\as.png")
    32. Dim a As New AutoItX3Lib.AutoItX3
    33. a.MouseClick("LEFT", res(1), res(2))
    34. End Sub
    35. End Class



    Edit:

    Wie Man die DLL unter 64Bit nutzen könnt kann man hier nachlesen: [VB 2008] Altes Thema Neue Frage ( ImageSearchDLL Reloaded )

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „vbler“ ()

    Mit Option Strict On wärst Du bereits fertig. :D
    Wenn Du ImageSearch mit dem Returnwert String deklarierst, musst Du den Returnwert auch einem String zuweisen.
    Unsd pack den Code aus der Form_Load raus!

    VB.NET-Quellcode

    1. Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    2. Dim result As String = ImageSearch(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, "C:\Temp\ImageSearch\Test.jpg")
    3. MessageBox.Show(result)
    4. End Sub
    Bilder
    • ImageSearch.jpg

      4,62 kB, 154×154, 1.037 mal angesehen
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!