is it possible to use autoit from newlisp

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
mostlywrong
Posts: 32
Joined: Fri Jan 09, 2009 10:54 pm

is it possible to use autoit from newlisp

Post by 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
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »


mostlywrong
Posts: 32
Joined: Fri Jan 09, 2009 10:54 pm

Post by mostlywrong »

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
Posts: 32
Joined: Fri Jan 09, 2009 10:54 pm

Post by mostlywrong »

seems the dll mentioned above was a custom job.

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

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
Posts: 32
Joined: Fri Jan 09, 2009 10:54 pm

Post by mostlywrong »

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
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

My undertsanding was so far, that the dll from autoit3 is a dual-mode DLL.
(ActiveX and regular DLL)
Hans-Peter

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Post by xytroxon »

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

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

Code: Select all

; 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 {\StandardDLL\DevC\AutoIt3.h}))
(setq header (parse (read-file AutoIt3_h) "\r\n"))

(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 "\")\r\n") code_header -1)
		(push
			(string
				";; " c_code "\r\n"
				"(define (" (4 func_call) ")\r\n"
				"\t(" func_call ")\r\n"
				")\r\n\r\n"
			)
			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
Posts: 32
Joined: Fri Jan 09, 2009 10:54 pm

Post by mostlywrong »

Thank you. This will be a nice challenge.

mostlywrong
Posts: 32
Joined: Fri Jan 09, 2009 10:54 pm

Post by mostlywrong »

quick question. In the above code. the import line in the generated file looks like this

Code: Select all

(import AutoItX3_dll "AU3_CDTrayLPCWSTR")
then header file line looks like so

Code: Select all

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
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Post by xytroxon »

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:

Code: Select all

      (dolist (str '("AU3_API" "WINAPI" "void" "const" "int" "long" "char" "(" "," ")" ";"))
Should look like this:

Code: Select all

      (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
Posts: 171
Joined: Wed Feb 14, 2007 12:54 pm
Location: Carifornia

Post by m35 »

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 old post where I wrote conversion functions before newLISP had native UTF-8 handling on Windows. That included this function.

Code: Select all

(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
Posts: 32
Joined: Fri Jan 09, 2009 10:54 pm

Post by mostlywrong »

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.
http://msdn.microsoft.com/en-us/library ... OT.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
Posts: 32
Joined: Fri Jan 09, 2009 10:54 pm

Post by mostlywrong »

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 ?

m35
Posts: 171
Joined: Wed Feb 14, 2007 12:54 pm
Location: Carifornia

Post by m35 »

mostlywrong wrote:ok, real question. windows does not Do utf-8?
It depends on what you mean by "do".
The core Windows API will only accept 1-byte-per-character strings that are localized with the current locale, or UTF-16 strings (as far as I know). But the Windows API also provides the MultiByteToWideChar and WideCharToMultiByte functions to convert between other types of strings.
mostlywrong wrote:it looks like the string in unicode are all 16bit unicode. how does that mesh with newlisps utf-8 ?
What string are you talking about?
newLISP doesn't really have a way to deal with UTF-16 strings, either in its ANSI version or its UTF-8 version. You have to convert between UTF-16 and either ANSI or UTF-8. You can do this with the win32api, another lib, or find the Unicode specifications and roll your own.

mostlywrong
Posts: 32
Joined: Fri Jan 09, 2009 10:54 pm

Post by mostlywrong »

sorry it looks like I dropped an S on the words strings in that sentence.

I am trying to understand what the differences between LPCSTR LPWSTR LPCWSTR.

How Utf-8 relates to it (because there is a utf-8 newlisp)

The desire to do the project that i first had in mind is a lot smaller now, but I would like get a little working knowledge of how to pass and convert to and from unicode.

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Post by xytroxon »

Here's a link to UTF-8 on Wikipedia:
http://en.wikipedia.org/wiki/UTF-8

And to UTF-16
http://en.wikipedia.org/wiki/UTF-16

-- xytroxon
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

Locked