Author Topic: unmanaged to managed object  (Read 2876 times)

0 Members and 1 Guest are viewing this topic.

Draftek

  • Water Moccasin
  • Posts: 1501
unmanaged to managed object
« on: November 22, 2006, 02:08:52 PM »
Can someone show me how to convert an autocad unmanaged object to a managed one in a wrapper class:

Code: [Select]
long TEST::Wrapper::Utils::TestHighlight(ObjectId &ID)
{
     AcDbObjectId * newid = new AcDbObjectId();

    // the unmanaged method
     highlightTest(*newid);

     return newid.asOldId();
}


I'm getting a long from the asOldId() method, but I'd really like to convert the unmanaged newid to the managed ID as the wrapper argument.

Thanks, cause I'm lost.

I tried using DisposableWrapper.Craate() but to no avail....
Soli Deo Gloria

MickD

  • Gator
  • Posts: 3242
  • !false...it's funny 'cause it's true!
Re: unmanaged to managed object
« Reply #1 on: November 22, 2006, 02:25:58 PM »
In the SDK, have a look at the mgdinterop header file (and include it in your projects) for some typical conversions of   typical items commonly used in these situations.

here's an example of getting an object id that I used to store objects in an array
Code: [Select]

//in the header:
public:
        void AddId(ObjectId entId); //add managed objId's to id array
private:
        AcDbObjectIdArray* _ids; //native storage of ObjId's
//------------------------------------------------------------------------------------//
//- in the cpp
void DCS_3D::HlrEngine::DCS2dEngine::AddId(ObjectId entId)
{
_ids->append(GETOBJECTID(entId));// use managed macro to convert id types
}

I've used this to write a very basic wrapper of some functions and classes, basically you just need a pointer to the native object inside your wrapper class and you can handle marshaling the input/output with those macros and methods in the mgdinterop.h

hth,
Mick.
A programmer's wife tells him, "Run to the store and pick up a loaf of bread. If they have eggs, get a dozen."

The programmer comes home with 12 loaves of bread.

Draftek

  • Water Moccasin
  • Posts: 1501
Re: unmanaged to managed object
« Reply #2 on: November 22, 2006, 02:30:38 PM »
sweet! Thanks.

I'll try that.

Get back with you as soon as I hose it....
Soli Deo Gloria

Draftek

  • Water Moccasin
  • Posts: 1501
Re: unmanaged to managed object
« Reply #3 on: November 22, 2006, 02:53:38 PM »
ooooOOOOO!

Thanks. If you knew how long today, I've been fighting this, you'd feel sorry for me. :)

If we ever meet, I owe you a beer - and not any watered-down American crap either.
Soli Deo Gloria

MickD

  • Gator
  • Posts: 3242
  • !false...it's funny 'cause it's true!
Re: unmanaged to managed object
« Reply #4 on: November 22, 2006, 02:59:59 PM »
....
If we ever meet, I owe you a beer - and not any watered-down American crap either.

I'll hold you to that :) , glad to be of some help.
A programmer's wife tells him, "Run to the store and pick up a loaf of bread. If they have eggs, get a dozen."

The programmer comes home with 12 loaves of bread.