PInvoke ObjectARX from .NET

PInvoke ObjectARX from .NET

Sinc
Advisor Advisor
673 Views
2 Replies
Message 1 of 3

PInvoke ObjectARX from .NET

Sinc
Advisor
Advisor
Here's a little guide to a procedure that can help a lot for people trying to customize Autocad using .NET:

http://www.quux.biz/Programming/PInvoke.aspx

This explains how to go about using that ObjectARX method that isn't exposed in the managed API. If you've been hanging out in this group for long, you've probably seen Tony Tanzillo solve problems using this trick. Now this article explains how to do it, so you can do it yourself.

And this brings up another useful tip for .NET programmers: remember to look at the ObjectARX documentation. Don't rely on intellisense or the docs for the managed API. There are a lot of things in ObjectARX that are not in the managed API, so if you aren't reading the ObjectARX documentation, you won't know certain access points even exist. The managed API documentation is still easier to use for many things, but when you are trying to find a way to accomplish a new task with the API, remember to look in the ObjectARX documentation for methods that are missing from the managed API.

-- Sinc
http://www.ejsurveying.com
http://www.quux.biz
http://www.sincpac3d.com
Sinc
0 Likes
674 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
>> Now this article explains how to do it, so you can do it yourself.

Nice article, but some key things one needs to know in order to DIY, were overlooked.

Getting the mangled signature is only one part of the puzzle (Depends.exe from www.dependencywalker.com is much better for that than dumpbin.exe, BTW).

The more complicated part of the puzzle is understanding how types are marshalled between native and managed code, e.g., knowing what managed type should be used for a given native type. That generally requires a basic understanding of C++ and C++ data types, pointers, and references. It also requires an understanding of the basic differences between how value types and reference types are handled (e..g, when a parameter in a P/Invoke declaration requires 'out' or 'ref').

Depends.exe can also halp with that, because it can display the undecorated C++ signature of a function which shows you the C++ types it takes and returns, and that's the key to figuring out the correct P/Invoke declaration.

So, while your artcle walks through one specific case, it really doesn't show one how they can do it themself, for any function.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

wrote in message news:5977168@discussion.autodesk.com...
Here's a little guide to a procedure that can help a lot for people trying to customize Autocad using .NET:

http://www.quux.biz/Programming/PInvoke.aspx

This explains how to go about using that ObjectARX method that isn't exposed in the managed API. If you've been hanging out in this group for long, you've probably seen Tony Tanzillo solve problems using this trick. Now this article explains how to do it, so you can do it yourself.

And this brings up another useful tip for .NET programmers: remember to look at the ObjectARX documentation. Don't rely on intellisense or the docs for the managed API. There are a lot of things in ObjectARX that are not in the managed API, so if you aren't reading the ObjectARX documentation, you won't know certain access points even exist. The managed API documentation is still easier to use for many things, but when you are trying to find a way to accomplish a new task with the API, remember to look in the ObjectARX documentation for methods that are missing from the managed API.

-- Sinc
http://www.ejsurveying.com
http://www.quux.biz
http://www.sincpac3d.com
0 Likes
Message 3 of 3

Sinc
Advisor
Advisor
Yeah, I know. I wasn't sure how far I wanted to get into that. As you know, the topic can quickly become a mess...

I think the article gives enough info for people to handle simple cases, like the one used as an example. I should probably also link to the Microsoft article I found that lists the most-important equivalencies between the C++ and C# types, though, for those who want to get into it further.

Someone else pointed me toward dependencywalker. I should probably add a mention of that to the article.

And then there's always stuff like this, which attempts to automatically determine the C# signature by parsing the C++ header files:

http://msdn.microsoft.com/en-us/magazine/cc164193.aspx
Sinc
0 Likes