is it possible to use autoit from newlisp

Started by mostlywrong, February 05, 2009, 05:58:15 PM

Previous topic - Next topic

mostlywrong

I sure it is. I'm also pretty sure I'm doing something wrong.



I tried a couple of the examples of importing functions into newlisp with the autoitx3.dll that is installed with autoit and Im not really getting any results, well any good ones.



The functions are all defined in the help files for autoit. There is much (almost nothing) about C that i don't understand though.

newdep

#1
Can you drop an example here of what your doing?



If its a pure C .dll its should not be any problem...
-- (define? (Cornflakes))

cormullion

#2
and did you search the forum?



http://www.alh.net/newlisp/phpbb/viewtopic.php?t=153&highlight=autoit">//http://www.alh.net/newlisp/phpbb/viewtopic.php?t=153&highlight=autoit

mostlywrong

#3
i did, i did search some.  now that i out in just autoit i see a ton more. feeling like a dope now. off to do some reading

mostlywrong

#4
seems the dll mentioned above was a custom job.

HPW

#5
I have edited the old link in the other thread to the correct web-page.



Note that it conatins the old AutoItX 2.X DLL



But there is not so much new stuff in the 3.X DLL.



The DLL was the original one from the autoit-projekt.

No custom DLL and the contained lsp file show imports and samples.
Hans-Peter

mostlywrong

#6
ok so the dll from autoit3 is an activex dll then and cant be imported.

looks lits possible to make a regular dll with what they have provided though.

HPW

#7
My undertsanding was so far, that the dll from autoit3 is a dual-mode DLL.

(ActiveX and regular DLL)
Hans-Peter

xytroxon

#8
Here is a script to help get started making a new AutoItX3 module.



Maybe HPW can host the final "autoitx3.lsp" version?



; Script: "make_au3.nlw" (for newLISP Windows version only)
; Function: To help in wrapping "AutoItX3.dll"
; from "AutoItX3.h" C header file
; to "autoitx3.lsp" newLISP module format
;
; 1. Download and install AutoIt3 from:
; http://www.autoitscript.com/autoit3/index.shtml
;
; 2. Run this script to create raw "autoitx3" file.
;
; 3. Edit functions and rename file to "autoitx3.lsp"
;
; Header error in version 3.2.12.1 (last Win 95 98 Me version)
; crashes script, so comment out this line:
; (import AutoItX3_dll "AU3_ControlTreeView")
;
; newLISP's module syntax: (AU3:FunctionName args)
; maps to C dll syntax: AU3_FunctionName(args)
;
; IMPORTANT: NOT all functions will work "out of the box"
; const char * and long (int) map to newLISP import interface
; other C data types will need conversions.
; Functions like AU3_ClipGet need a return buffer
; So use allocate funtion etc. See code from HPW's site:
; http://www.alh.net/newlisp/phpbb/viewtopic.php?t=153&highlight=autoit
;
; 4. To test functions, enter newLISP REPL
;
; (load "autoitx3.lsp")
; (AU3:Init)
; (AU3:ClipPut "Hello AutoIt3X.dll World!")
;
; Then paste clip buffer to your editor.
; If editor shows: Hello AutoIt3X.dll World!
; Success!!!

(setq file_paths
[text]
(setq AutoIt3_path (string (env "PROGRAMFILES") {AutoIt3}))
(setq AutoItX_path (string AutoIt3_path {AutoItX}))
(setq AutoItX3_dll (string AutoItX_path {AutoItX3.dll}))

[/text]
)

(eval-string file_paths) ; need location of AutoIt3 for both scripts

(setq AutoIt3_h (string AutoItX_path {StandardDLLDevCAutoIt3.h}))
(setq header (parse (read-file AutoIt3_h) "rn"))

(setq code_header "" code_body "")

(define (strip line)
(setq line
(dolist (str '("AU3_API" "WINAPI" "void" "const" "int" "long" "char" "(" "," ")" ";"))
(replace str line "")
)
)
(setq line (replace {/*.*?*/} line "" 0))
(setq line (replace {   } line " "))
(setq line (replace {  } line " "))
(setq line (replace {*} line ""))
(setq line (trim line))
)

(dolist (c_code header)
(when (starts-with c_code "AU3_API")
(setq func_call (strip c_code))
(setq func_name (0 (find " " (string func_call " ")) func_call))
(push (string "(import AutoItX3_dll "" func_name "")rn") code_header -1)
(push
(string
";; " c_code "rn"
"(define (" (4 func_call) ")rn"
"t(" func_call ")rn"
")rnrn"
)
code_body
-1
)
)
)

(write-file "autoitx3"
(string
[text]
;; @module autoitx3.lsp
;; @description AutoIt3X.dll Win32 interface module
;; @version 0.0
;; @author xytroxon, others?

(context 'AU3)
[/text]
file_paths
code_header
[text]
; Put needed conversion funtions here.

(define (allocate n) ; From HPW & Nigel from the newLISP forum
(pack (string "s" n)" ")
)

; AutoItX3 functions:

[/text]
code_body
[text]
(context MAIN)

[/text]
)
)

(exit)



-- xytroxon
\"Many computers can print only capital letters, so we shall not use lowercase letters.\"

-- Let\'s Talk Lisp (c) 1976

mostlywrong

#9
Thank you. This will be a  nice challenge.

mostlywrong

#10
quick question. In the above code. the import line in the generated file looks like this(import AutoItX3_dll "AU3_CDTrayLPCWSTR")
 then header file line looks like so AU3_API long WINAPI AU3_CDTray(LPCWSTR szDrive, LPCWSTR szAction);
 The "LPCWSTR" doesnt belong there, where would the edit go to fix the name in your script?



I think ill learn more from your script than all of my fiddling around.

xytroxon

#11
And I also "learned" why the lastest AutoIt3 release doesn't work on my old Win98 laptop ;)



Keeping track of three kinds of string pointers, LPCSTR LPWSTR LPCWSTR must be better than keeping track of just one char pointer type. LOL!!!



You will need to add "LPCSTR" "LPWSTR" "LPCWSTR" to "make_au3.nl"



This line:

     (dolist (str '("AU3_API" "WINAPI" "void" "const" "int" "long" "char" "(" "," ")" ";"))


Should look like this:

     (dolist (str '("AU3_API" "WINAPI" "void" "const" "int" "long" "char" "LPCSTR" "LPWSTR" "LPCWSTR" "(" "," ")" ";"))


Unfortunately, this also makes wrapping the dll harder!



The latest AutoIt3 supports Microsoft's version of UTF coding.



There is a UTF-8 Windows version of newLISP you can download and use...



Internally Apple uses UTF-8 and Microsoft uses UTF-16 for XP and later versions... Not sure how they are converted to each other's format...



And that is about the limit of my (poor) knowledge on interfacing UTF code!!!



-- xytroxon
\"Many computers can print only capital letters, so we shall not use lowercase letters.\"

-- Let\'s Talk Lisp (c) 1976

m35

#12
I haven't looked at the declarations of the AutoIt3 dll functions, but do the "LPCSTR" "LPWSTR" "LPCWSTR" mean that they have different versions of functions can accept ANSI (LPC), or UTF-16 (LPW) or ?? (LPCW?)?



Assuming that, obviously the ANSI versions are no problem. For the UTF-16 versions, you're right that you'll need that extra step to convert newLISP ANSI or UTF-8 into UTF-16 before calling those functions.



There's an http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1694">old post where I wrote conversion functions before newLISP had native UTF-8 handling on Windows. That included this function.


(import "kernel32.dll" "MultiByteToWideChar")
(constant 'SIZEOF_WCHAR 2)
(constant 'CP_UTF8 65001) ; code page 65001 = UTF-8

(define (utf8->16 lpMultiByteStr , cchWideChar lpWideCharStr ret)

    ; calculate the size of buffer (in WCHAR's)
    (setq cchWideChar (MultiByteToWideChar
        CP_UTF8 ; from UTF-8
        0       ; no flags necessary
        lpMultiByteStr
        -1      ; convert until NULL is encountered
        0
        0
    ))
   
    ; allocate the buffer
    (setq lpWideCharStr (dup " " (* cchWideChar SIZEOF_WCHAR)))
   
    ; convert
    (setq ret (MultiByteToWideChar
        CP_UTF8 ; from UTF-8
        0       ; no flags necessary
        lpMultiByteStr
        -1      ; convert until NULL is encountered
        lpWideCharStr
        cchWideChar
    ))
    (if (> ret 0) lpWideCharStr nil)
)


The additional utf16->8, ansi->utf16, and utf16->ansi would be similar (see also the WideCharToMultiByte win32api function). You could also check the newLISP source win32-path.c for the same kind of code written in C.

mostlywrong

#13
Its never something easy is it.     :-)



edit:

Well now i know (sorta) what "LPCSTR" "LPWSTR" "LPCWSTR" is and i cant really think of anything constructive to say.


Quotehttp://msdn.microsoft.com/en-us/library/cc245847%28PROT.10%29.asp">http://msdn.microsoft.com/en-us/library ... OT.10).asp">http://msdn.microsoft.com/en-us/library/cc245847(PROT.10).asp

An LPCSTR is a 32-bit pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters.

An LPCWSTR is a 32-bit pointer to a constant string of 16-bit UNICODE characters, which MAY be null-terminated.

The LPWSTR type and its alias PWSTR specifies a pointer to a sequence of UNICODE characters, which MAY be terminated by a null character (usually referred to as "null-terminated Unicode").

after reading that i now know i am dealing with a 32bit pointer pointing at something that might have a null terminator or it may not and could be 2x longer.

mostlywrong

#14
ok, real question. windows does not Do utf-8?



it looks like the string in unicode are all 16bit unicode. how does that mesh with newlisps utf-8 ?