Hello,
I have a in-process .NET dll library written in C#.
Now I need to use the library from a ARX application (expose its methods, make calls passing parameters and returning results).
Is it possible at all?
I can call use a out-of-process .NET dll from ARX, but I can't make it work for a in-process one.
Any help/pointers/samples will be much appreciated.
Thanks
alex
You can either export interface functions from the .arx that you call from the .NET DLL via P/Invoke, or you can make your .arx a mixed mode that directly references the .NET DLL and calls it directly from C++/CLI.
Owen,
Thank you for replying.
I saw a few articles on the net about using a c++/cli wrapper to bridge between the native c++ arx and the c# library dll.
I could use a simple sample to set me on the right path.
One more question: given that the c# dll library is in fact a autocad .net dll, how does it get loaded? Is it loaded by the /cli wrapper or by manual netload? and if the former, how does autocad recognize it?
alex
Sorry, there is no such thing as a simple example of C++/CLI calling a managed DLL. Managed code resolves referenced code on demand, so your dependent DLL gets loaded (rather, the JIT compiled assembly code gets loaded -- managed code doesn't "load") on demand when your code calls it.
I'm working on one now. it's up and going. Nighmareish at first but suddenly it doesn't seem so bad. I say this after a month of no sleep when things are suddenly going ok. Last week my response may have been different...
Use the SimpleSquare project as a starting point, then look at PolySamp which is more complicated and more correct after. the COM in PolySamp is optional.
if you have any specific questions I'll help where I can, but I'm no expert. I will say having a Enterprise version of Visual studio pays off here as you can build dependency graphs and the like of the sample projects. that's a big help (or was for me).
edit: oh, i'm vb not c# just to warn ya 😉
c++ should unite us all though lol.
Never mind the VB part. It's OK.
I had a look at the SimpleSquare sample but it's the other way around. What I need is to expose managed functions defined in a NET module to C++ARX; the above sample exposes ARX module functionality to NET (if I understood it right).
Got anything along those lines?
Thanks.
Things are just never the way we want them lol.
I had to chuckly - by definition, I think you want an "un-managed wrapper". I don't know why that makes me chuckle, but it does.
First, I make this up as I go along, so I can't tell u what can be done, just what I have proved. My instincts after over a month at this full time so not likely - even if you could, the extra code wouldn't be worth it. My goal was to do the minimal c++ / objectARX custom stuff, wrap it and get back to vb.net for the interface of the project... but I should say when I do have to code in c++ for stuff it seems much quicker, if less safe, so maybe I should have done the whole thing there 😕 but I digress...sorry.
I don't have managed functions or objects moving back but I DO have data bi-directional. So all attemps to pass Polyline into that world and convert / cast it to AcDbPolyline there have failed (not saying not possible just I failed...) but passing an ObjectID of a polyline DID work with some effort. I posted my fun experimenting with that here:
the thing in that solution to really look at was this:
Autodesk::AutoCAD::Runtime::Interop::Check(GetImpObj()->ConstructPoly(GETOBJECTID(value)));
with:
GETOBJECTID(value)
being the big deal. there seem to be predefined functions that convert vb managed types back to c++ unmanged types(c++ to vb types is obvious from the Simple square, other way, not so much). Good luck finding these functions, I would love to see a list of them. I ended up digging through PolySamp - it had more examples of passed back data. still I do have
myCustomDrivedPoly(vbPolylineObjectID)
working - i pass it a ObjectID of a managed Polyline and get it to build a AcDbPolyine in C++ without too much stress.
I never got
myCustomDrivedPoly(vbPolylineObject)
to work, and gave up bothering. again, the code to copy the Polyline data into my AcDbPolyine was like half that of vb...I keep wishing I could write more code modules there but it's not usually worth the hassle.
I think if your doing mixed managed memory projects you have to do workarounds like this, but again not an expert, just a traveller....don't know if that helps or not, but I hope it does something.
Feel free to keep in touch, we seem to be in similar boats lol (or start a support group for fellow sufferers, whatever...)