Page 1 of 1

DLL call with 'ARRAY OF PCHAR' possible?

Posted: Wed Dec 08, 2004 7:55 am
by HPW
I want to call such a exported delphi function:

Code: Select all

FUNCTION MyExportedFunction( Param1 : INTEGER;  VAR Params : ARRAY OF PChar ) : BOOLEAN;
Is it possible to call a function with an 'ARRAY OF PCHAR' from newLISP?

Posted: Wed Dec 08, 2004 1:05 pm
by Lutz
I assume "ARRAY of PCHAR" means "char * string[]". There is an example about this here: http://www.newlisp.org/index.cgi?page=C ... _Libraries

towards the end of the page:

Code: Select all

parameter   newLISP Call                      called function
type

String []    (foo (pack "ld ld ld 
                     (address "one")           foo(char * string[])
                     (address "two")
                     (assress "three")))  
So you basically pack 32bit addresses of strings one after the other. I assume that "Param1":

MyExportedFunction( Param1 : INTEGER; VAR Params : ARRAY OF PChar )

contains the size of the array? or perhaps you have to pass the last member of the array as a null/0 ? somehow the Dephi function must know how big the array is!

Lutz

Posted: Wed Dec 08, 2004 8:43 pm
by HPW
In fact it is not my function, it is the original neobook interface:

Code: Select all

(import "hpwImage.nbp" "nbExecAction")

(nbExecAction (pack "ld" (address 3))(pack "ld ld ld ld ld ld" (address "RImage1")(address "10")(address "10")(address "50")(address "50")(address "clRed")))
And the integer is a function identifier to know which function is called.
But no success, it get only a ZERO back.
I am thinking to make a special wrapper-function for this.

Posted: Wed Dec 08, 2004 9:01 pm
by Lutz
You dont need to pack the first parameter you can just pass the '3':

(nbExecAction 3 (pack "ld ld ld ld ld ld" (address "RImage1")(address "10")(address "10")(address "50")(address "50")(address "clRed")))


if the function is:

nbExecAction( Param1 : INTEGER; VAR Params : ARRAY OF PChar )

Lutz

Posted: Thu Dec 09, 2004 8:39 am
by HPW
Still no success with that.
I have asked on a delphi forum what so special with 'ARRAY OF PCHAR'

In the meantime I have made a solution, based on only using simple PCHAR. That is working fine.

Now I search a elegant LISP which does this:

From a list like this:
(("DllCmd1" "1" 3)
("DllCmd2" "2" 4)
("DllCmd3" "3" 5))
1: Commandname
2: Commandindex
3: Number of Param

generate this:

Code: Select all

(set (sym "DllCmd1") (lambda (nbpara1 nbpara2 nbpara3)
              (DllExec "1" nbpara1 nbpara2 nbpara3)))
(set (sym "DllCmd2") (lambda (nbpara1 nbpara2 nbpara3 nbpara4)
              (DllExec "2" nbpara1 nbpara2 nbpara3 nbpara4)))
(set (sym "DllCmd3") (lambda (nbpara1 nbpara2 nbpara3 nbpara4 nbpara5)
              (DllExec "3" nbpara1 nbpara2 nbpara3 nbpara4 nbpara5)))
What is the best way?

Posted: Thu Dec 09, 2004 12:03 pm
by HPW
My first try:

Code: Select all

(setq dllcmdlst '(("DllCmd1" "1" 3)("DllCmd2" "2" 4)("DllCmd3" "3" 5)))

(define (test )
 (dolist (cmdlst dllcmdlst)
	(begin
	(setq nbparastr1 "")
	(setq nbparastr2 (string "DllExec \"" (nth 1 cmdlst) "\" "))
	(for (x 1 (last cmdlst)1)
		(begin
		(setq nbparastr1 (string nbparastr1 "nbpara" x " "))
		(setq nbparastr2 (string nbparastr2 "nbpara" x " "))))
	(set(sym (first cmdlst))
		(eval-string (string "'(lambda (" nbparastr1 ")(" nbparastr2 "))")))
	)
 )
)
Suggestions?