Hi Dan.
I've actually been doing a lot of C++/CLI programming with
AutoCAD development. For most other types of development,
C# is preferred, unless you must call native C++ apis, as is
the case with ObjectARX.
One of the coolest things about C++/CLI is something called
"implicit P/Invoke", where calling native code requires only
the .h file with the native function/class declarations, and
requires no [DllImport] declarations, and so you can easily
use native C++ classes, from managed C++/CLI, in an almost
completely transparent way.
For AutoCAD development, C++/CLI is actually a better
choice than C# given sufficient skills, because it makes
accessing the entire native C++ ObjectARX API easy.
For example, to deal with the problem the managed
SymbolTable class has with the indexer returning erased
entries, I wrote this in C++/CLI, which lets me call the
underlying AcDbSymbolTableRecord directly from managed
code:
// Returns ObjectId.Null if non-erased record is not found.
static ObjectId^ GetSymbolTableRecordId(SymbolTable^ table, String^ name)
{
AcDbSymbolTable* tbl = dynamic_cast<AcDbSymbolTable*>(table->UnmanagedObject.ToPointer());
if( tbl == NULL )
throw gcnew InvalidOperationException("Invalid SymbolTable object");
if( String::IsNullOrEmpty(name) )
throw gcnew System::ArgumentException("Invalid SymbolTable name");
tbl->assertReadEnabled();
AcDbObjectId id;
id.setNull();
Acad::ErrorStatus es = tbl->getAt(StringToWchar(name), id, false);
if( es == Acad::eOk )
return ObjectId(id.asOldId());
else
return ObjectId(); // not found or erased
}
Has anyone looked at the new C++/CLR syntax that VC2005 uses? It’s actually pretty cool. I never even considered using C++ with .NET. I was always scared of all those macros like __gc. But after playing around with it, I found it quite pleasant. It seems C++ might just be the language of choice for people who want to just stick with one language and program using managed and/or unmanaged code.