TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mailmaverick on August 29, 2016, 11:55:57 AM

Title: Load C++ DLL from LISP
Post by: mailmaverick on August 29, 2016, 11:55:57 AM
How can I load and use C++ DLL by LISP ?
My C++ code is as under :-
Code: [Select]
int _stdcall useArray(double* dIn1, double* dIn2, double* dOut)
{

;; My code here

}

Source.def has been defined as :
Code: [Select]
LIBRARY "useArray"
EXPORTS
MyFunction = useArray

This function takes input values dIn1 and dIn2 as arrays and gives output in dOut as an array again.
Title: Re: Load C++ DLL from LISP
Post by: ChrisCarlson on August 29, 2016, 12:14:51 PM
Wait, do you want to load a .DLL file from AutoLISP or load a .LSP from a .DLL?
Title: Re: Load C++ DLL from LISP
Post by: mailmaverick on August 29, 2016, 12:26:01 PM
I have a .DLL file created in C++ which has a function named useArray.

I want to use this DLL in AutoLISP.
Title: Re: Load C++ DLL from LISP
Post by: ChrisCarlson on August 29, 2016, 12:30:28 PM
Well if the .DLL is loaded, simply call it like you would any other command.

Code - Auto/Visual Lisp: [Select]
  1. (useArray)

Code - Auto/Visual Lisp: [Select]
  1. (setq var (useArray var1 var2))

If it is not loaded

Code - Auto/Visual Lisp: [Select]
  1. (command "_NETLOAD" "useArray.dll")
Title: Re: Load C++ DLL from LISP
Post by: dgorsman on August 29, 2016, 12:36:03 PM
Ah, well that depends if the DLL actually defines a LISP function.  If it doesn't, then if it implements COM methods/properties those can be accessed through (vlax-invoke-method ...) and (vlax-get/set-property ...).  If neither of those then it cannot be used through LISP.
Title: Re: Load C++ DLL from LISP
Post by: mailmaverick on August 29, 2016, 02:38:50 PM
(command "_NETLOAD" "useArray.dll") returns NIL, it does not load.

DLL does not define a LISP function but is a pure C++ DLL.

I think  dgorsman's vlax-invoke-method can be used.

But how.
Title: Re: Load C++ DLL from LISP
Post by: ChrisCarlson on August 29, 2016, 03:34:53 PM
In order to netload to work, the DLL needs to be in a folder read by AutoCAD.
Title: Re: Load C++ DLL from LISP
Post by: dgorsman on August 29, 2016, 04:45:13 PM
(command "_NETLOAD" "useArray.dll") returns NIL, it does not load.

DLL does not define a LISP function but is a pure C++ DLL.

I think  dgorsman's vlax-invoke-method can be used.

But how.

Those require the DLL to have a COM interface.  If its "pure C++" with no COM interface then you still cannot call directly using LISP.  If you cannot add LISP functions to the DLL you would need to roll-your-own DLL wrapper to provide the appropriate LISP functions.
Title: Re: Load C++ DLL from LISP
Post by: MickD on August 29, 2016, 04:54:33 PM
(command "_NETLOAD" "useArray.dll") returns NIL, it does not load.

DLL does not define a LISP function but is a pure C++ DLL.

I think  dgorsman's vlax-invoke-method can be used.

But how.


dgorsman is correct, there is no way to load this dll unless it exposes a COM interface or it is created as an ObjectARX application that exposes a Lisp function interface. The NETLOAD command is used to load .Net assembly dll's, you can't load a native (C++) dll with NETLOAD.

If this was written by youself or you know the person perhaps you can ask them to write it in .Net, that is the easiest way forward IMO.
<added> actually, you would need to expose the .Net dll with a Lisp interface as well, to hook different runtime tecnnologies you need to provide some way for them to talk to each other and these interfaces are what make that possible.
Title: Re: Load C++ DLL from LISP
Post by: mailmaverick on August 30, 2016, 04:42:38 PM
Thanks for your comments.

I want to use LISPLAB as given at https://common-lisp.net/project/lisplab/ in Autolisp / Visual LISP.

Can you help me on this.
Title: Re: Load C++ DLL from LISP
Post by: ur_naz on September 03, 2016, 06:00:25 PM
How can I load and use C++ DLL by LISP ?
Just look here https://bitbucket.org/mmamkin/mtmdloaddll
Title: Re: Load C++ DLL from LISP
Post by: MickD on September 03, 2016, 07:15:06 PM
that looks good ur_naz!

Will it handle the LISPLAB lib if it doesn't have a COM interface? I couldn't easily tell by looking at the code which by the way is pretty cool and heavy duty, I will be studying that for a while :)
Title: Re: Load C++ DLL from LISP
Post by: baitang36 on September 22, 2022, 12:11:09 AM
How can I load and use C++ DLL by LISP ?
My C++ code is as under :-
Code: [Select]
int _stdcall useArray(double* dIn1, double* dIn2, double* dOut)
{

;; My code here

}

Source.def has been defined as :
Code: [Select]
LIBRARY "useArray"
EXPORTS
MyFunction = useArray

This function takes input values dIn1 and dIn2 as arrays and gives output in dOut as an array again.
Lisp can load dlls. A reserved function load-dll is required
This function autodesk is not exposed. The reserved function needs to be converted before it can be used. Look here http://bbs.mjtd.com/thread-185974-1-1.html?_dsign=674e21e0
Title: Re: Load C++ DLL from LISP
Post by: domenicomaria on September 22, 2022, 03:01:56 PM
Quote
Lisp can load dlls.
A reserved function load-dll is required
This function autodesk is not exposed.
The reserved function needs
to be converted before it can be used.

Look here 
http://bbs.mjtd.com/thread-185974-1-1.html?_dsign=674e21e0


I am studying lsp to directly call windows api.
After success, lsp will be as powerful
as other languages
​​and do whatever you want

This Is very interesting ...
Title: Re: Load C++ DLL from LISP
Post by: xdcad on November 22, 2023, 06:23:42 PM
Quote
Lisp can load dlls.
A reserved function load-dll is required
This function autodesk is not exposed.
The reserved function needs
to be converted before it can be used.

Look here
http://bbs.mjtd.com/thread-185974-1-1.html?_dsign=674e21e0


I am studying lsp to directly call windows api.
After success, lsp will be as powerful
as other languages
​​and do whatever you want

This Is very interesting ...

xdrx-load-dll
xdrx-unload-dll