B
Bern McCarty
I have a DLL written in C++ (it's really C code that was adjusted to compile
OK as C++) that I compile successfully into IL with the /CLR switch of
Visual C 7.1. I use the resultant library successfully from other C++ code
(both native and managed) and it works fine. I would like to figure out the
shortest and most convenient path to making this library callable from other
..NET languages. The function signatures in this librariy's API are really
pretty simple. There are a small handful of value types (C structs) passed
by reference (pointer) to lots of functions. So how to arrange for these
functions to be callable from say, C#, by passing value types as reference
or out parameters?
The first problem that I see is that the library is just a bunch of
functions in the global namespace and C# apparently doesn't let you look up
anything in the global namespace except other namespaces so the functions
aren't accessible. This, if I understand correctly, is to be addressed in
Whidbey.
The next problem is that it looks like the the Visual C++ compiler defines
..NET value types to represent my C structs to the managed world with dummy
definitions. If run ildasm on my mixed DLL and have a look I will see that
my C structure which looked like this in C++
struct dPoint3d {double x; double y; double z;};
....get's represented on the managed side as a value type with nothing in it
like this:
.class /*02000006*/ public sequential ansi sealed 'dPoint3d'
extends ['mscorlib'/* 23000001 */]'System'.'ValueType'/* 01000003 */
{
} // end of class 'dPoint3d'
I can see how it is that the C++ compiler was nevertheless able to generate
the correct IL for my functions; afterall it had the real definitions of
these structs from my header files. It was the compiler's decision to make
the corresponding .NET value types opaque to the rest of the world by not
filling them in. So how might I arrange to have these value types made
"real" so that this API can be called from other .NET languages? Is there a
secret VisualC++ compiler switch that will get it to define these types
fully? Some other way to make this API callable from C#?
Bern McCarty,
Bentley Systems, Inc.
OK as C++) that I compile successfully into IL with the /CLR switch of
Visual C 7.1. I use the resultant library successfully from other C++ code
(both native and managed) and it works fine. I would like to figure out the
shortest and most convenient path to making this library callable from other
..NET languages. The function signatures in this librariy's API are really
pretty simple. There are a small handful of value types (C structs) passed
by reference (pointer) to lots of functions. So how to arrange for these
functions to be callable from say, C#, by passing value types as reference
or out parameters?
The first problem that I see is that the library is just a bunch of
functions in the global namespace and C# apparently doesn't let you look up
anything in the global namespace except other namespaces so the functions
aren't accessible. This, if I understand correctly, is to be addressed in
Whidbey.
The next problem is that it looks like the the Visual C++ compiler defines
..NET value types to represent my C structs to the managed world with dummy
definitions. If run ildasm on my mixed DLL and have a look I will see that
my C structure which looked like this in C++
struct dPoint3d {double x; double y; double z;};
....get's represented on the managed side as a value type with nothing in it
like this:
.class /*02000006*/ public sequential ansi sealed 'dPoint3d'
extends ['mscorlib'/* 23000001 */]'System'.'ValueType'/* 01000003 */
{
} // end of class 'dPoint3d'
I can see how it is that the C++ compiler was nevertheless able to generate
the correct IL for my functions; afterall it had the real definitions of
these structs from my header files. It was the compiler's decision to make
the corresponding .NET value types opaque to the rest of the world by not
filling them in. So how might I arrange to have these value types made
"real" so that this API can be called from other .NET languages? Is there a
secret VisualC++ compiler switch that will get it to define these types
fully? Some other way to make this API callable from C#?
Bern McCarty,
Bentley Systems, Inc.