Author Topic: Mixed/Managed C++ dll's, passing objects.  (Read 14716 times)

0 Members and 1 Guest are viewing this topic.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #30 on: November 09, 2009, 04:54:37 AM »
Thanks Daniel, I wont get a chance to test for a day or so as I have other commitments but it looks good.
I'm squeesing this coding in between jobs so I really appreciate your help here, I feel a bit guilty for not putting in the study learning the clr stuff but I really only need these few pieces to get me through so again, thanks heaps, I owe you a beer or three :)
cheers.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.
- J.R.R. Tolkien

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #31 on: November 10, 2009, 09:37:35 PM »
Thanks Daniel, works a treat now, cheers :)

Kerry, I'll send you something soon ;)
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.
- J.R.R. Tolkien

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #32 on: November 10, 2009, 09:56:27 PM »

Take your hurry. (translated : in your own time ... I used to have an Irish neighbour when I was a kid.)

Thanks Mick.






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.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #33 on: November 10, 2009, 10:30:10 PM »
Thanks Daniel, works a treat now, cheers :)

Great! please send beer or black licorice to:

Lane 99 PuMing Rd. Bldg #26 Apt#1403
Shanghai, China, 200120

 JK :-D

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #34 on: November 11, 2009, 02:58:27 AM »
Never mind, I just found a small box of Good&Plenty, an extremely rare item in this part of the world.. ah bliss  :love:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #35 on: November 11, 2009, 03:27:13 AM »

I'll get some Darell Lee in to a bag :)

.. and some Rocklea Road ??
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.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #36 on: November 11, 2009, 05:54:45 AM »

I'll get some Darell Lee in to a bag :)

.. and some Rocklea Road ??

Ah YES! Please send me the bill too  :wink:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #37 on: November 12, 2009, 03:38:19 AM »

The carton is packed and addressed  ... in the mail tomorrow.

there is a bonus of some earwax flavoured jelly beans to try :)

.. will take a couple of days to reach you.

In appreciation !



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.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #38 on: November 13, 2009, 05:13:38 AM »
Wow! Awesome! Thank you!
I will reciprocate with goodies I have found over here!   :kewl:

csharpbird

  • Newt
  • Posts: 64
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #39 on: November 15, 2009, 02:56:51 AM »
Hi,Daniel
How to covert a managed ResultBuffer object to an unmanaged resbuf?
How to covert an unmanaged resbuf object to a managed ResultBuffer?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #40 on: November 15, 2009, 03:56:45 AM »
Pretty much the same way, if wrapper derives from Autodesk.AutoCAD.Runtime.DisposableWrapper, you can use the methods Create and get_UnmanagedObject


Code: [Select]
resbuf *pRb = reinterpret_cast<resbuf*>(resultBuffer->UnmanagedObject.ToPointer());

//and

ResultBuffer ^resultBuffer =
  dynamic_cast<ResultBuffer^>(DisposableWrapper::Create(ResultBuffer::typeid,(IntPtr)pRb,false));

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #41 on: January 14, 2010, 09:05:02 PM »
Hi Dan,
I've been pulling my hair out wondering why I can't get this finished :(
then I started looking at what I was passing around, I removed all the managed params and it worked fine so I looked a bit closer at what the conversion macros provided in the sdk were doing and I was getting mixed results.

Anyway, I've decided to do these conversions myself so I started with the snippet above but it errors out with 'UnManagedObject is not a member of .....blah blah'

Here's what I have

AcGePoint3d* p1 = reinterpret_cast<AcGePoint3d*>(pnt1->UnmanagedObject.ToPointer());

where pnt1 is passed in as Point3d^

the macro from adsk is -

#define GETPOINT3D(point3d) (*reinterpret_cast<AcGePoint3d*>(&(point3d)))

If I pass it a straight Point3d it spits out 0,0,0 regardless of point data, if I use a Point3d^ it spits out something like 33568899003 (a memory address or garbage??).

So, how is the best way to convert it to native, thanks.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.
- J.R.R. Tolkien

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #42 on: January 14, 2010, 09:54:15 PM »
Doh!!

I changed it to Point3d (without the ^) in my params and the arx macros works fine.

Sheesh, some consistency would be nice :roll:
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.
- J.R.R. Tolkien

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #43 on: January 14, 2010, 10:14:24 PM »
 :lol:  well I made these for you

Code: [Select]
void Wrapper::NativeToManaged()
 {
   AcGePoint3d npnt(1,1,1);//stack
   AcGePoint3d *pnpnt = new AcGePoint3d(2,2,2);//heap

   Point3d mpnt1 =  ToPoint3d( npnt );
   acutPrintf(_T("\n%g,%g,%g"),mpnt1.X,mpnt1.Y,mpnt1.Z);

   Point3d mpnt2 =  ToPoint3d( *pnpnt );
   acutPrintf(_T("\n%g,%g,%g"),mpnt2.X,mpnt2.Y,mpnt2.Z);

   Point3d ^pmpnt1 =  %ToPoint3d( npnt );
   acutPrintf(_T("\n%g,%g,%g"),pmpnt1->X,pmpnt1->Y,pmpnt1->Z);

   Point3d ^pmpnt2 =  %ToPoint3d( *pnpnt );
   acutPrintf(_T("\n%g,%g,%g"),pmpnt2->X,pmpnt2->Y,pmpnt2->Z);

   delete pnpnt;
 }

 void Wrapper::ManagedToNative()
 {
   Point3d mpnt(3,3,3); //stack
   Point3d ^pmpnt = gcnew  Point3d(4,4,4);//heap

   AcGePoint3d npnt1 =  GETPOINT3D( mpnt );
   acutPrintf(_T("\n%g,%g,%g"),npnt1.x,npnt1.y,npnt1.z);

   AcGePoint3d npnt2 =  GETPOINT3D( (Point3d)*pmpnt );
   acutPrintf(_T("\n%g,%g,%g"),npnt2.x,npnt2.y,npnt2.z);

   AcGePoint3d *pnpnt1 =  &GETPOINT3D( mpnt );
   acutPrintf(_T("\n%g,%g,%g"),pnpnt1->x,pnpnt1->y,pnpnt1->z);

   AcGePoint3d *pnpnt2 =  &GETPOINT3D( (Point3d)*pmpnt );
   acutPrintf(_T("\n%g,%g,%g"),pnpnt2->x,pnpnt2->y,pnpnt2->z);
 }

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: Mixed/Managed C++ dll's, passing objects.
« Reply #44 on: January 14, 2010, 10:21:39 PM »
I would try to keep those value types on the stack so you're not running into pinning pointers and stuff.