title: Call functions in AutoIt DLL using Python ctypes
body: <p>I want to call functions from an AutoIt dll, that I found at <em>C:\Program Files (x86)\AutoIt3\AutoItX\AutoItX3.dll</em> using Python. I know I could use <code>win32com.client.Dispatch("AutoItX3.Control")</code> but I can't install the application or register anything in the system.</p>
  
  <p>So far, this is where I am:</p>
  
  <pre><code>from ctypes import *
  path = r"C:\Program Files (x86)\AutoIt3\AutoItX\AutoItX3.dll"
  autoit = windll.LoadLibrary(path)
  </code></pre>
  
  <p>Here are the methods that works:</p>
  
  <pre><code>autoit.AU3_WinMinimizeAll() # windows were successfully minimized.
  autoit.AU3_Sleep(1000) # sleeps 1 sec.
  </code></pre>
  
  <p>Here is my problem, python is crashing when I call other methods like this one. I get <em>python.exe has stopped working</em> from windows...</p>
  
  <pre><code>autoit.AU3_WinGetHandle('Untitled - Notepad', '')
  </code></pre>
  
  <p>And some other methods are not crashing python but are just not working. This one doesn't close the window and return 0:</p>
  
  <pre><code>autoit.AU3_WinClose('Untitled - Notepad', '')
  </code></pre>
  
  <p>And this other one return 1 but the window is still minimized:</p>
  
  <pre><code>autoit.AU3_WinActivate('Untitled - Notepad', '')
  </code></pre>
  
  <p>I've tested the examples with with <code>Dispatch("AutoItX3.Control")</code> and everything is working like expected.</p>
  
  <p>It seems like methods that should return something other than a string are crashing python. But still, others like <code>WinClose</code> are not even working...</p>
  
  <p>Thank you in advance for your help!</p>
  
  <p>EDIT:</p>
  
  <p>These methods are now working when using unicode strings:</p>
  
  <pre><code>autoit.AU3_WinClose(u'Untitled - Notepad', u'')
  autoit.AU3_WinActivate(u'Untitled - Notepad', u'')
  </code></pre>
  
  <p>And I found the prototype for <code>AU3_WinGetHandle</code>:</p>
  
  <blockquote>
    <p>AU3_API void WINAPI AU3_WinGetHandle(const char <em>szTitle,
    /</em>[in,defaultvalue("")]*/const char *szText, char *szRetText, int
    nBufSize);</p>
  </blockquote>
  
  <p>Now I can retrieve the return value using the following code!</p>
  
  <pre><code>from ctypes.wintypes import LPCWSTR
  s = LPCWSTR(u'')
  print AU3_WinGetHandle(u'Untitled - Notepad', u'', s, 100) # prints 1
  print s.value # prints '000705E0'!
  </code></pre>
  
  <p>Thank you to those who helped me!</p>