Author Topic: Getting arguments to/from a custom activex function  (Read 6161 times)

0 Members and 1 Guest are viewing this topic.

SIDESHOWBOB

  • Guest
Getting arguments to/from a custom activex function
« on: December 15, 2011, 09:07:08 AM »
Hello creatures from the Swamp!  I wonder if you can help me.

I have written a COM dll that exports the function
Code - C++: [Select]
  1. hresult timestwo(double in,double* out)
  2. {
  3.    *out = in*2;
  4.    return S_OK;
  5. }

I am now trying to use it in visual lisp.

Code - Auto/Visual Lisp: [Select]
  1. (setq myinstance (vlax-create-object "myactivexlibrary.MyClass"))
  2. (vlax-dump-object myinstance 1) ; succeeds - myinstance shows up as having a method called timestwo

Presumably I can then call it with (vlax-invoke-method myinstance timestwo).  But how do I create the double and double* datatypes needed as arguments?

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Getting arguments to/from a custom activex function
« Reply #1 on: December 15, 2011, 09:46:29 AM »
This should work:
Code: [Select]
(setq num 12.34)
(vlax-invoke-method myinstance 'timestwo num 'newnum)
(princ (strcat "Result of 'timestwo' method = " (rtos newnum)))
« Last Edit: December 15, 2011, 09:57:30 AM by Jeff_M »

SIDESHOWBOB

  • Guest
Re: Getting arguments to/from a custom activex function
« Reply #2 on: December 15, 2011, 09:53:06 AM »
It fails:
Code - Auto/Visual Lisp: [Select]
  1. $ (vlax-invoke-method myinstance timestwo num 'newnum)
  2. ; error: bad argument type: (or stringp symbolp): nil
  3.  

Btw does ' mean "pointer to"?

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: Getting arguments to/from a custom activex function
« Reply #3 on: December 15, 2011, 09:59:06 AM »
Nope. No pointers in Autolisp. We have SET which "can operate in the spirit" of pointers. ...kinda. ...Oh, well Im gonna go back to just saying `nope' on the pointer thing.

The single quote symbol: See the QUOTE function (click the word below; its a link).
Code - Auto/Visual Lisp: [Select]
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Getting arguments to/from a custom activex function
« Reply #4 on: December 15, 2011, 10:00:41 AM »
I had a few typo's in the code sample....I blame a lack of coffee....the code has been edited.


SIDESHOWBOB

  • Guest
Re: Getting arguments to/from a custom activex function
« Reply #5 on: December 15, 2011, 10:07:37 AM »
Excellent!  Thank you.

While we're at it, is there a way to do that for arrays?  Do I need to go read the docs for safearray?

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Getting arguments to/from a custom activex function
« Reply #6 on: December 15, 2011, 12:55:06 PM »
Do the same thing for any type of return object. Then it's a matter of knowing the type once in lisp. So if you want to return an array, this would be similar to what the coordinates property of a polyline returns:

(note, vl-sel is my own helper function to select on object and return the vl-object instead of an ename)

Command: (setq plobj (vl-sel))

Select object: #<VLA-OBJECT IAcadLWPolyline2 000000002eb94a48>

Command: (setq coords (vlax-get-property plobj 'coordinates))
#<variant 8197 ...>

Command: (vlax-safearray->list (vlax-variant-value coords))
(3244.69 8968.45 3627.96 8607.93 3537.78 8247.4 3875.97 7999.53)

Yes, this is a property which returns the value, but a method which has an out parameter will work the same way. I should also note that the quoted property or method can be either a single quoted symbol name as I did, or as a string (wrapped in double quotes)...either way works fine. (vlax-invoke-method myinstance "timestwo" num 'newnum)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Getting arguments to/from a custom activex function
« Reply #7 on: December 15, 2011, 09:40:04 PM »
Nope. No pointers in Autolisp. We have SET which "can operate in the spirit" of pointers. ...kinda. ...Oh, well Im gonna go back to just saying `nope' on the pointer thing.

The single quote symbol: See the QUOTE function (click the word below; its a link).
Code - Auto/Visual Lisp: [Select]


John, the link to the help documentation is VERY cool .. well done !!

Regards
kdub
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: Getting arguments to/from a custom activex function
« Reply #8 on: December 15, 2011, 09:46:56 PM »
John, the link to the help documentation is VERY cool .. well done !!

Regards
kdub

Leave out the "the link to the help documentation" part and you got a deal my friend. *lol*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Getting arguments to/from a custom activex function
« Reply #9 on: December 15, 2011, 09:58:24 PM »
Leave out the "the link to the help documentation" part and you got a deal my friend. *lol*

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Getting arguments to/from a custom activex function
« Reply #10 on: December 15, 2011, 10:49:02 PM »

:)

Is that John's new avater ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Getting arguments to/from a custom activex function
« Reply #11 on: December 15, 2011, 11:17:03 PM »
could be:



 :-D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: Getting arguments to/from a custom activex function
« Reply #12 on: December 15, 2011, 11:31:15 PM »
Eeyore walked all round Tigger one way, and then turned and walked round him the other way.
"What did you say it was?" he asked.
"Tigger."
"Ah!" said Eeyore.
"He's just come," explained Piglet.
"Ah!" said Eeyore again.
He thought for a long time and then said: "When is he going?"



*smile*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SIDESHOWBOB

  • Guest
Re: Getting arguments to/from a custom activex function
« Reply #13 on: December 16, 2011, 10:27:04 AM »
Thanks all :) A A Milne appreciation aside...

Command: (vlax-safearray->list (vlax-variant-value coords))

So does this mean I have to send arrays back and forth packaged inside variants, there is no way to send a double array directly?  What if the C function is e.g
Code - C++: [Select]
  1. HRESULT arraytimestwo(double* in,double** out,long length)
is there a way to call that from vl or do I have to rewrite the C to accommodate variants?

Edit: I tried this...
Code - Auto/Visual Lisp: [Select]
  1. _$ (vlax-invoke-method n 'arraytimestwo safearray 'newsafearray arraylength)
  2. ; error: lisp value has no coercion to VARIANT with this type:  #<safearray...>
« Last Edit: December 16, 2011, 10:30:19 AM by SIDESHOWBOB »