Author Topic: Finding unmanaged function from 3rd party addon  (Read 3430 times)

0 Members and 1 Guest are viewing this topic.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Finding unmanaged function from 3rd party addon
« on: January 16, 2012, 07:58:58 AM »
We have a third party addon for AutoCAD and I've found an obvious call to it, "entity_query" in some existing lisp routines.  The call is "entity_query" in autolisp with a single parameter the entity. I'd like to be able to call this same function in .NET.  I've used Dependency Walker on all the DLLs that come with the addon and found nothing even close and the few functions I have found have no parameters shown in Dependency Walker.  I also tried using Dependency Walker on the .arx files but was unable to pull anything from them.  I'm looking for a suggestion on what to do next.  Is there a way to call the lisp routine from within my .NET code and get the results it returns in lisp?  Is there a better way to see the functions contained in an .arx file?
Revit 2019, AMEP 2019 64bit Win 10

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Finding unmanaged function from 3rd party addon
« Reply #1 on: January 16, 2012, 09:06:58 AM »
Amending post:

"entity_query" is called with a vla-object of the entity.  If I call this function with acedInvoke what is the type of the parameter in .NET, DBObject?
Revit 2019, AMEP 2019 64bit Win 10

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8858
  • AKA Daniel
Re: Finding unmanaged function from 3rd party addon
« Reply #2 on: January 16, 2012, 09:22:22 AM »
the arx might be a COM server, is there an installer? if so, search the registry.
if you find an entry, you have a good chance at being able to call it from .NET  :-)

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Finding unmanaged function from 3rd party addon
« Reply #3 on: January 16, 2012, 10:22:06 AM »
No such luck. Can't find "entity_query" anywhere in the registry.  Thanks though.

Still looking for how to pass a vla-object from .NET and then I can use acedInvoke if I can't find a way to call directly from arx file.
Revit 2019, AMEP 2019 64bit Win 10

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: Finding unmanaged function from 3rd party addon
« Reply #4 on: January 16, 2012, 10:58:36 AM »
Amending post:

"entity_query" is called with a vla-object of the entity.  If I call this function with acedInvoke what is the type of the parameter in .NET, DBObject?
Are you sure that parameter is vla-object of the entity, not entity name?
In order to call lisp-function from .NET with acedInvoke this lisp-function *MUST* be registered  with help of (vl-acad-defun 'function_name)

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Finding unmanaged function from 3rd party addon
« Reply #5 on: January 16, 2012, 12:47:52 PM »
Alexander, I believe it is the entity name and a 3d point and not a vla-object.  I'm assuming that the entity name is the ObjectId in hex format.
Revit 2019, AMEP 2019 64bit Win 10

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Finding unmanaged function from 3rd party addon
« Reply #6 on: January 16, 2012, 12:57:59 PM »
Are there any other files included with this addon? How is the function called? Are you certain that it isn't a defined function in another lisp file?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Finding unmanaged function from 3rd party addon
« Reply #7 on: January 16, 2012, 01:06:14 PM »
Yes, I am certain that this is not another defined lisp routine.  I searched through every known lisp routine we have and it wasn't there.  When I open the lisp file up in VLIDE the command is blue just like every other built in command. So i assumed that confirmed my suspicions of it being part of the addons API.

There are other files included with the addon. They include .ARX files, a few .DLL files and some database files. I can use Dependency Walker and see whats being called from the .DLLs but Dependency Walker wont show me any of the functions in the .ARX files.

EDIT:
If I try and run the command from the command line with no parameters (entity_query).  I get an error window with the name of one of the .ARX files. Would that mean that it's definition should be in that file somewhere?  If I open the .ARX up in a hex editor I cannot find the string "entity_query" within the file.
« Last Edit: January 16, 2012, 01:40:42 PM by MexicanCustard »
Revit 2019, AMEP 2019 64bit Win 10

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Finding unmanaged function from 3rd party addon
« Reply #8 on: January 16, 2012, 03:16:14 PM »
Thanks to an old post by Tony T - http://forums.autodesk.com/t5/NET/How-to-call-Lisp-functions-from-Net/td-p/1564636

I was able to conquer the Lisp side of this this.  Here is a little test just to see if it would work.

Code - C#: [Select]
  1. [CommandMethod("GETDATA")]
  2.         public void GetData()
  3.         {
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Database db = doc.Database;
  6.             Editor ed = doc.Editor;
  7.  
  8.             using (Transaction tr = db.TransactionManager.StartTransaction())
  9.             {
  10.                 BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
  11.                 BlockTableRecord modelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
  12.  
  13.                 PromptEntityOptions peo = new PromptEntityOptions("\nSelect Entity: ");
  14.                 PromptEntityResult per = ed.GetEntity(peo);
  15.  
  16.                 ResultBuffer args = new ResultBuffer();
  17.                 int stat = 0;
  18.  
  19.                 args.Add(new TypedValue((int)LispDataType.Text, "entity_query"));
  20.                 args.Add(new TypedValue((int)LispDataType.ObjectId, per.ObjectId));
  21.                 args.Add(new TypedValue((int)LispDataType.Point3d, new Point3d(0,0,0)));
  22.  
  23.                 ResultBuffer res = InvokeLisp(args, ref stat);
  24.                 if (stat == 5100 && res != null)
  25.                     PrintResbuff(res);
  26.  
  27.                 res.Dispose();
  28.                 tr.Commit();
  29.  
  30.             }
  31.         }
  32.  
  33.         private void PrintResbuff(ResultBuffer res)
  34.         {
  35.             string s = "\n--------------------";
  36.             foreach (TypedValue val in res)
  37.             {
  38.                 s += string.Format("\n{0}->{1}", val.TypeCode, val.Value.ToString());
  39.             }
  40.             s += "\n---------------------";
  41.  
  42.             Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(s);
  43.         }
  44.  
  45.         [System.Security.SuppressUnmanagedCodeSecurity]
  46.         [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
  47.         extern static private int acedInvoke(IntPtr args, out IntPtr result);
  48.  
  49.         public ResultBuffer InvokeLisp(ResultBuffer args, ref int stat)
  50.         {
  51.             IntPtr rb = IntPtr.Zero;
  52.             stat = acedInvoke(args.UnmanagedObject, out rb);
  53.             if (stat == (int)PromptStatus.OK && rb != IntPtr.Zero)
  54.                 return (ResultBuffer)DisposableWrapper.Create(typeof(ResultBuffer), rb, true);
  55.  
  56.             return null;
  57.         }
  58.  

Now if anyone has any ideas on calling functions contained in the .ARX directly that would be better but in the meantime its working.
Revit 2019, AMEP 2019 64bit Win 10