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

0 Members and 1 Guest are viewing this topic.

SIDESHOWBOB

  • Newt
  • Posts: 91
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

  • Gator
  • Posts: 3453
  • 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

  • Newt
  • Posts: 91
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"?

John Kaul (Se7en)

  • Needs a day job
  • Posts: 7140
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]
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

Jeff_M

  • Gator
  • Posts: 3453
  • 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

  • Newt
  • Posts: 91
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

  • Gator
  • Posts: 3453
  • 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: 10383
  • 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
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate<--

John Kaul (Se7en)

  • Needs a day job
  • Posts: 7140
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*
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

MP

  • Seagull
  • Posts: 16174
  • Warning: I may be trolling.
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*

\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | Dropbox | O'Reilly School | UltraEdit

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 10383
  • 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 ??
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate<--

MP

  • Seagull
  • Posts: 16174
  • Warning: I may be trolling.
Re: Getting arguments to/from a custom activex function
« Reply #11 on: December 15, 2011, 11:17:03 pm »
could be:



 :-D
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | Dropbox | O'Reilly School | UltraEdit

John Kaul (Se7en)

  • Needs a day job
  • Posts: 7140
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*
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

SIDESHOWBOB

  • Newt
  • Posts: 91
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 »