newLISP callback into Autocad?

Q&A's, tips, howto's
Locked
HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

newLISP callback into Autocad?

Post by HPW »

Hello,

Inspired by this articel:

https://github.com/davidbl/acadhelper/w ... o-AutoLISP

I tried similar from newLISP.exe to a running instance of autocad 2006
(I checked the exported function name with dependency walker.)

Code: Select all

newLISP v.10.4.0 on Win32 IPv4/6, execute 'newlisp -h' for more info.

> (import "C:\\Programme\\AutoCAD 2006\\acad.exe" "?acedEvaluateLisp@@YAHPBDAAPA
Uresbuf@@@Z" "cdecl")
?acedEvaluateLisp@@YAHPBDAAPAUresbuf@@@Z@11745F0
>
Import seems to get the entry point.
But when I try

Code: Select all

(setq resbuffer "                       ")
(?acedEvaluateLisp@@YAHPBDAAPAUresbuf@@@Z "(setq Test1 100)" resbuffer)
newLISP crashes.

Any idea what can be wrong?

Regards

Hans-Peter
Hans-Peter

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: newLISP callback into Autocad?

Post by Lutz »

No idea, what is going on, but perhaps you have more luck with the extended FFI import:

Code: Select all

(set 'acedEvaluateLisp 
    (import ""C:\\Programme\\AutoCAD 2006\\acad.exe" "?acedEvaluateLisp@@YAHPBDAAPA
Uresbuf@@@Z" "int" "char*" "void*"))
At the same time, the function is also renamed to something more manageable.

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

Re: newLISP callback into Autocad?

Post by HPW »

I tried this:

Code: Select all

newLISP v.10.4.0 on Win32 IPv4/6, execute 'newlisp -h' for more info.

> (set 'acedEvaluateLisp (import "C:\\Programme\\ACAD2006\\acad.exe" "?acedEvalu
ateLisp@@YAHPBDAAPAUresbuf@@@Z" "int" "char*" "void*"))
?acedEvaluateLisp@@YAHPBDAAPAUresbuf@@@Z@BE3390
> (setq resbuffer "                       ")
"                       "
>(acedEvaluateLisp resbuffer "(setq Test1 100)")
but agian I get a crash.
Do I call it right with the buffer and the order of the parameter?

Regards
Hans-Peter
Hans-Peter

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: newLISP callback into Autocad?

Post by Lutz »

Yes, you are doing everything right. For 'resbuffer' , which is supposed to be a pointer to an integer, 4 bytes would be sufficient e.g. (setq resbuffer "\000\000\000\000") for 32-bit AutoCad. But there is nothing wrong to reserve more and initializing with anyhting else than zero's. If I understand the Ruby import declaration correctly, this is strictly and output parameter. But just to be safe, you might try to initialize with binary 0's. Googling for acedEvaluateLisp, I saw somebody innitializing the prt to zero when calling the function.

Perhaps the best would be, not to go by the Ruby example, but look at the original call pattern and declaration for "?acedEvaluateLisp@@YAHPBDAAPAUresbuf@@@Z" or "acedEvaluateLisp". This strange sequence of characters surrounding the real name "acedEvaluateLisp" seems to be some king of name mangling by a compiler or pre-processor. Perhaps AutoCad is written in C++ and the magled name is the C-compatible derivative.

I somehow expected thuis outcome, because the call pattern as I understand it, is well suited for the simple FFI import in newLISP (pointers and integers). So using the extended FFI shouldn't really make a difference in this case.

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

Re: newLISP callback into Autocad?

Post by HPW »

... but look at the original call pattern and declaration for "?acedEvaluateLisp@@YAHPBDAAPAUresbuf@@@Z" or "acedEvaluateLisp".
Unfourtunatly the function is undocumented and unsupported by autodesk.
I tried the resbuffer with "\000\000\000\000" but still get a crash.
And yes AutoCad is written in C++.
But it seems to work from ruby, so my hope was to get access to the engine without any helper-DLL in .NET.
Or might it be a problem to call it from EXE to EXE?
I think the ruby thing is build with ironruby from inside a .NET extension in Autocad.

Regards

Hans-Peter
Hans-Peter

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

Re: newLISP callback into Autocad?

Post by HPW »

Hans-Peter

Locked