Author Topic: P/Invoke the acedGrRead function  (Read 3195 times)

0 Members and 1 Guest are viewing this topic.

itcad

  • Guest
P/Invoke the acedGrRead function
« on: November 07, 2008, 08:47:51 AM »
Which is the correct syntax to P/Invoke the acedGrRead function, specially the third argument?
This code is wrong:
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        extern static public int acedGrRead(int track, int type, double[] output);
        public void LAcedGrRead()
        {
            int track = 1, type = new int();
            double[] output = new double[3];
            while (track > 0)
            {
                acedGrRead(track, type, output);
                if (type == 3) track = 0
            }
        }

Who can tell me the right code?

TonyT

  • Guest
Re: P/Invoke the acedGrRead function
« Reply #1 on: November 07, 2008, 09:20:21 AM »
Which is the correct syntax to P/Invoke the acedGrRead function, specially the third argument?
This code is wrong:
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        extern static public int acedGrRead(int track, int type, double[] output);
        public void LAcedGrRead()
        {
            int track = 1, type = new int();
            double[] output = new double[3];
            while (track > 0)
            {
                acedGrRead(track, type, output);
                if (type == 3) track = 0
            }
        }

Who can tell me the right code?

There's really no need to use acedGrRead() in ObjectARX these days.

That's a legacy API that does not work (because it disables all kinds
of things like use of menus and so forth), and that's why You shouldn't
use it to start with.

To arrive at the same functionality, you add a handler to the Editor's
PointMonitor event just before you call it's GetPoint() method, and
remove the handler after the GetPoint() call returns.

In the handler, you can get the cursor location, draw temporary graphics,
query the objects in the aperture/pickbox, and do other things that you
can't easily do via acedGrRead().


itcad

  • Guest
Re: P/Invoke the acedGrRead function
« Reply #2 on: November 08, 2008, 06:46:07 AM »
Which is the correct syntax to P/Invoke the acedGrRead function, specially the third argument?
This code is wrong:
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        extern static public int acedGrRead(int track, int type, double[] output);
        public void LAcedGrRead()
        {
            int track = 1, type = new int();
            double[] output = new double[3];
            while (track > 0)
            {
                acedGrRead(track, type, output);
                if (type == 3) track = 0
            }
        }

Who can tell me the right code?

There's really no need to use acedGrRead() in ObjectARX these days.

That's a legacy API that does not work (because it disables all kinds
of things like use of menus and so forth), and that's why You shouldn't
use it to start with.

To arrive at the same functionality, you add a handler to the Editor's
PointMonitor event just before you call it's GetPoint() method, and
remove the handler after the GetPoint() call returns.

In the handler, you can get the cursor location, draw temporary graphics,
query the objects in the aperture/pickbox, and do other things that you
can't easily do via acedGrRead().



It hasn,t  the Editor's PointMonitor in autocad2005,so I need use acedGrRead.

TonyT

  • Guest
Re: P/Invoke the acedGrRead function
« Reply #3 on: November 09, 2008, 01:46:48 AM »
Which is the correct syntax to P/Invoke the acedGrRead function, specially the third argument?
This code is wrong:
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        extern static public int acedGrRead(int track, int type, double[] output);
        public void LAcedGrRead()
        {
            int track = 1, type = new int();
            double[] output = new double[3];
            while (track > 0)
            {
                acedGrRead(track, type, output);
                if (type == 3) track = 0
            }
        }

Who can tell me the right code?

There's really no need to use acedGrRead() in ObjectARX these days.

That's a legacy API that does not work (because it disables all kinds
of things like use of menus and so forth), and that's why You shouldn't
use it to start with.

To arrive at the same functionality, you add a handler to the Editor's
PointMonitor event just before you call it's GetPoint() method, and
remove the handler after the GetPoint() call returns.

In the handler, you can get the cursor location, draw temporary graphics,
query the objects in the aperture/pickbox, and do other things that you
can't easily do via acedGrRead().



It hasn,t  the Editor's PointMonitor in autocad2005,so I need use acedGrRead.


I think this is what you need:

Code: [Select]

public class Class1
{
   [DllImport( "acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode )]
   public extern static int acedGrRead( int track, out int code, IntPtr result );

   public static void Example()
   {
      int track = 1;
      int code = 0;
      IntPtr p = IntPtr.Zero;

      acedGrRead( track, out code, p );
      if( p != IntPtr.Zero )
      {
         using( ResultBuffer buffer = ResultBuffer.Create( p, true ) )
         {

             // Here, the coordinate result is in buffer, if
             // the code output parameter indicates that a
             // coordinate result was returned
         }
      }
   }
}



itcad

  • Guest
Re: P/Invoke the acedGrRead function
« Reply #4 on: November 09, 2008, 05:03:51 AM »
Which is the correct syntax to P/Invoke the acedGrRead function, specially the third argument?
This code is wrong:
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        extern static public int acedGrRead(int track, int type, double[] output);
        public void LAcedGrRead()
        {
            int track = 1, type = new int();
            double[] output = new double[3];
            while (track > 0)
            {
                acedGrRead(track, type, output);
                if (type == 3) track = 0
            }
        }

Who can tell me the right code?

There's really no need to use acedGrRead() in ObjectARX these days.

That's a legacy API that does not work (because it disables all kinds
of things like use of menus and so forth), and that's why You shouldn't
use it to start with.

To arrive at the same functionality, you add a handler to the Editor's
PointMonitor event just before you call it's GetPoint() method, and
remove the handler after the GetPoint() call returns.

In the handler, you can get the cursor location, draw temporary graphics,
query the objects in the aperture/pickbox, and do other things that you
can't easily do via acedGrRead().



It hasn,t  the Editor's PointMonitor in autocad2005,so I need use acedGrRead.


I think this is what you need:

Code: [Select]

public class Class1
{
   [DllImport( "acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode )]
   public extern static int acedGrRead( int track, out int code, IntPtr result );

   public static void Example()
   {
      int track = 1;
      int code = 0;
      IntPtr p = IntPtr.Zero;

      acedGrRead( track, out code, p );
      if( p != IntPtr.Zero )
      {
         using( ResultBuffer buffer = ResultBuffer.Create( p, true ) )
         {

             // Here, the coordinate result is in buffer, if
             // the code output parameter indicates that a
             // coordinate result was returned
         }
      }
   }
}




I try to use your code,but it's wrong.
please try again.

TonyT

  • Guest
Re: P/Invoke the acedGrRead function
« Reply #5 on: November 09, 2008, 11:16:47 AM »
Code: [Select]

public static void Example()
{
   int track = 1;
   int code = 0;
   ResultBuffer buffer = new ResultBuffer(
      new TypedValue[] { new TypedValue( 5009, Point3d.Origin ) } );

   acedGrRead( track, out code, buffer.UnmanagedObject );

   if( code == 5 )
   {
      TypedValue[] values = buffer.AsArray();
      Console.Write( values[0].Value );
   }
}


It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6934
  • AKA Daniel
Re: P/Invoke the acedGrRead function
« Reply #6 on: November 09, 2008, 12:04:34 PM »
Has anyone ever tried using C++/CLI  /CLR:Pure on 05?

TonyT

  • Guest
Re: P/Invoke the acedGrRead function
« Reply #7 on: November 09, 2008, 04:37:42 PM »
Has anyone ever tried using C++/CLI  /CLR:Pure on 05?

I haven't tried much of anything on '05. 

It's ancient history here.