Author Topic: Marshaling and ARX  (Read 2741 times)

0 Members and 1 Guest are viewing this topic.

MickD

  • Gator
  • Posts: 3244
  • !false...it's funny 'cause it's true!
Marshaling and ARX
« on: March 26, 2006, 05:37:32 PM »
Has anyone had a go at marshaling wrapped arx object classes to an unmanaged arx dll??
I've had some success passing strings (std .net types) accross but was wondering if anyone has an example of passing the managed lib objects.
There are 2 ways I could achieve this,
1) is by writing a managed wrapper of the functions in arx (the prefered method)
2) is by using DllImport in .net.
either way though requires marshaling to the required types.

For simple things like vectors and points I could pass the parameters as doubles and create the arx object using these in the constructors but how would you go with a list of object ID's for example??

I'll try and knock up a simple example to work with using DllImport and go from there.
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.

MickD

  • Gator
  • Posts: 3244
  • !false...it's funny 'cause it's true!
Re: Marshaling and ARX
« Reply #1 on: March 26, 2006, 06:33:44 PM »
Ok, moving on...
It seems I can get to the unmanaged object through the DisposableWrapper, of course I couldn't find this property in the point and vector wrappers which threw me off a bit at first (as they are simply an array of doubles they don't require to be an RxObject I guess).

So, I think I will be doing this directly in C++ as a managed wrapper dll where I can mix both managed and unmanaged together.

Could a moderator move this thread to the ARX section please, sorry for the inconvenience.
Thanks,
Mick.

<edit> Thanks Chuck </edit>
« Last Edit: March 26, 2006, 07:37:18 PM by MickD »
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.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16716
  • Superior Stupidity at its best
Re: Marshaling and ARX
« Reply #2 on: March 27, 2006, 08:40:42 AM »
Perhaps I am misunderstanding something ... but if you import the dll or you build the application as an ARX, there should be no marshalling ... unless you meant something else ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

MickD

  • Gator
  • Posts: 3244
  • !false...it's funny 'cause it's true!
Re: Marshaling and ARX
« Reply #3 on: March 27, 2006, 04:39:50 PM »
I need to use some arx functionality that isn't available in the .net api so I have to use mixed MC++ and C++ to create my own wrappers to have access to these functions from .net.

Importing an unmanaged dll works ok for a COM type library (as it has an interface that handles/coerces 'types') but with mixing managed and unmanaged you are crossing context boundaries from managed (garbage collected) to unmanaged and vice versa.
As the arx api for .net are only wrappers around standard arx objects they have a pointer to these unmanaged objects which is what I need but I have to pass the managed object to my C++ unmanaged functions first, hence the wrapper.

Here's an example of wrapping a simple arx function I wrote for 2005 to register app names and that show's some of the type 'coercing' involved. This could now be imported into a C#/vb.net app for use with .net.
Code: [Select]
#include "stdafx.h"

#include "ArxGlobals.h"
#include "acutads.h"
using namespace ArxGlobals;
using System::Runtime::InteropServices::Marshal;

void GlobalFuncs::RegApp(String * appName)
{
static const char __nogc* pStr1 = static_cast<char*>(Marshal::StringToHGlobalAnsi(appName).ToPointer());
int retVal = acdbRegApp(pStr1);
if(retVal == RTNORM)
{
acutPrintf ("Added application name!\n") ;
return;
}
if(retVal == RTERROR)
{
acutPrintf("Application name already added!\n");
return;
}
else
{
acutPrintf("Failed to add application name :(\n");
}
return;
}
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.