title: Implement ImageSearchDLL.dll in C#
body: <p>I am trying to use ImageSearchDLL.dll in Visual Studio C#. I used to use it in AutoIt.</p>
  
  <p>Following is the code I came up with to use the <a href="http://www.autoitscript.com/forum/topic/148005-imagesearch-usage-explanation/" rel="nofollow">Imagesearch</a> Function. However, as soon as it tried to call ImageSearch, the program crashes without any exception.
  I have the dll file included in my project folder. Could it be because of that although I was able to use the dll in AutoIt, it doesn't mean it would work in C# as well?
  Note: I tried both 32 and 64 bits of .dll</p>
  
  <pre><code>    [DllImport("ImageSearchDLL.dll")]
      static extern string ImageSearch(int aLeft, int aTop, int aRight, int aBottom, string aImageFile);
  
      public static int Search(String FilePath, int X1, int Y1, int X2, int Y2, ref int X, ref int Y, int tolerance, int resultPosition)
      {
          if (tolerance &gt; 0) 
          {
              FilePath = "*" + tolerance.ToString() + " " + FilePath;
          }
  
          string result = ImageSearch(X1, Y1, X2, Y2, "test.png"); **&lt;- crash here**
          string[] result_array = result.Split('|');
          if (result_array[0] == "0" )
              return 0;
          X = Convert.ToInt32(result_array[2]);
          Y = Convert.ToInt32(result_array[3]);
          if (resultPosition == 1)
          {
              X = X + (Convert.ToInt32(result_array[4]))/2;
              Y = Y + (Convert.ToInt32(result_array[5]))/2;
          }
          return 1;       
      }
  </code></pre>