Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Lisp: how to call functions in external C++ DLL

I have a C++ dll I have written (native, not .net), and I would like to use its functionality from Visual Lisp. Can anyone point me to an example of how to do this, or at least which bit of documentation to read?

like image 763
Sideshow Bob Avatar asked Dec 12 '11 16:12

Sideshow Bob


People also ask

What is the difference between AutoLISP and Visual LISP?

AutoLISP in AutoCAD offers functions for interactive data entry, processing and access to the AutoCAD drawing database ( DWG ). VisualLISP (originally "Vital LISP ") was added to AutoCAD in the versions R14 (as an add-on) and 2000 (integrated).


2 Answers

I solved this by writing an activex/COM wrapper for my dll, which I think should make it easier to link to in future. Starting a thread on the swamp yielded some answers from nice people about how to call COM from Visual Lisp. For the record, it looks something like this:

//in c++... (header and IDL file also needed)
hresult timestwo(double in,double* out)
{
  *out = in*2;
  return S_OK;
}

;; in Lisp...
(vl-load-com)
(setq myinstance (vlax-create-object "mycomwrapperdll.mycomwrapperclass"))
(setq num 12.34)
(vlax-invoke-method myinstance 'timestwo num 'newnum)
(vlax-release-object myinstance)
;; newnum now contains 24.68
like image 177
Sideshow Bob Avatar answered Nov 15 '22 15:11

Sideshow Bob


You expose your native C++ code to AutoLisp using the acedDefun() and acedRegFunc() API calls.

Here is a discussion on Autodesk's programming forum asking exactly your question.

like image 32
Rodney Schuler Avatar answered Nov 15 '22 14:11

Rodney Schuler