Author Topic: Load C++ DLL from LISP  (Read 4974 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 494
Load C++ DLL from LISP
« 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.

ChrisCarlson

  • Guest
Re: Load C++ DLL from LISP
« Reply #1 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?

mailmaverick

  • Bull Frog
  • Posts: 494
Re: Load C++ DLL from LISP
« Reply #2 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.

ChrisCarlson

  • Guest
Re: Load C++ DLL from LISP
« Reply #3 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")

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Load C++ DLL from LISP
« Reply #4 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.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

mailmaverick

  • Bull Frog
  • Posts: 494
Re: Load C++ DLL from LISP
« Reply #5 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.

ChrisCarlson

  • Guest
Re: Load C++ DLL from LISP
« Reply #6 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.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Load C++ DLL from LISP
« Reply #7 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.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Load C++ DLL from LISP
« Reply #8 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.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

mailmaverick

  • Bull Frog
  • Posts: 494
Re: Load C++ DLL from LISP
« Reply #9 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.
« Last Edit: August 30, 2016, 05:31:33 PM by mailmaverick »

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: Load C++ DLL from LISP
« Reply #10 on: September 03, 2016, 06:00:25 PM »

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Load C++ DLL from LISP
« Reply #11 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 :)
« Last Edit: September 03, 2016, 07:19:13 PM by MickD »
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

baitang36

  • Bull Frog
  • Posts: 213
Re: Load C++ DLL from LISP
« Reply #12 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

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: Load C++ DLL from LISP
« Reply #13 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 ...

xdcad

  • Bull Frog
  • Posts: 429
Re: Load C++ DLL from LISP
« Reply #14 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
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
[XDrx-Sub Forum]
https://www.theswamp.org/index.php?board=78.0
https://github.com/xdcad/XDrx-API
http://bbs.xdcad.net