newLISP callback into Autocad?

Started by HPW, February 20, 2012, 01:39:11 AM

Previous topic - Next topic

HPW

Hello,



Inspired by this articel:



https://github.com/davidbl/acadhelper/wiki/Ruby-talks-to-AutoLISP">https://github.com/davidbl/acadhelper/w ... o-AutoLISP">https://github.com/davidbl/acadhelper/wiki/Ruby-talks-to-AutoLISP



I tried similar from newLISP.exe to a running instance of autocad 2006

(I checked the exported function name with dependency walker.)



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

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

newLISP crashes.



Any idea what can be wrong?



Regards



Hans-Peter
Hans-Peter

Lutz

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



(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

#2
I tried this:

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

#3
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 "00000000") 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

#4
Quote
... 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 "00000000" 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

#5
Another vb.net sample:



http://forums.autodesk.com/t5/forums/forumtopicprintpage/board-id/152/message-id/17709/print-single-message/true/page/1">http://forums.autodesk.com/t5/forums/fo ... rue/page/1">http://forums.autodesk.com/t5/forums/forumtopicprintpage/board-id/152/message-id/17709/print-single-message/true/page/1
Hans-Peter