DLL call with 'ARRAY OF PCHAR' possible?

Started by HPW, December 07, 2004, 11:55:59 PM

Previous topic - Next topic

HPW

I want to call such a exported delphi function:



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


Is it possible to call a function with an  'ARRAY OF PCHAR' from newLISP?
Hans-Peter

Lutz

#1
I assume "ARRAY of PCHAR" means "char * string[]". There is an example about this here: http://www.newlisp.org/index.cgi?page=Compiling_and_Importing_Libraries">http://www.newlisp.org/index.cgi?page=C ... _Libraries">http://www.newlisp.org/index.cgi?page=Compiling_and_Importing_Libraries



towards the end of the page:



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

HPW

#2
In fact it is not my function, it is the original neobook interface:



(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.
Hans-Peter

Lutz

#3
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

HPW

#4
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:
Quote
(("DllCmd1" "1" 3)

 ("DllCmd2" "2" 4)

 ("DllCmd3" "3" 5))


1: Commandname

2: Commandindex

3: Number of Param



generate this:



(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?
Hans-Peter

HPW

#5
My first try:



(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?
Hans-Peter