Code Red > .NET

P/Invoke the acedGrRead function

(1/2) > >>

itcad:
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:

--- Quote from: itcad 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?

--- End quote ---

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:

--- Quote from: TonyT on November 07, 2008, 09:20:21 AM ---
--- Quote from: itcad 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?

--- End quote ---

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().



--- End quote ---

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

TonyT:

--- Quote from: itcad on November 08, 2008, 06:46:07 AM ---
--- Quote from: TonyT on November 07, 2008, 09:20:21 AM ---
--- Quote from: itcad 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?

--- End quote ---

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().



--- End quote ---

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

--- End quote ---


I think this is what you need:


--- Code: ---
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
         }
      }
   }
}



--- End code ---

itcad:

--- Quote from: TonyT on November 09, 2008, 01:46:48 AM ---
--- Quote from: itcad on November 08, 2008, 06:46:07 AM ---
--- Quote from: TonyT on November 07, 2008, 09:20:21 AM ---
--- Quote from: itcad 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?

--- End quote ---

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().



--- End quote ---

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

--- End quote ---


I think this is what you need:


--- Code: ---
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
         }
      }
   }
}



--- End code ---


--- End quote ---

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

Navigation

[0] Message Index

[#] Next page

Go to full version