Assembly with shared __nogc class

E

Edward Diener

I want to share a __nogc classes between different assemblies. For __gc
classes, one only needs to declare the class public in order to be able to
do this. Is there a way to share a __nogc class so that I can access its
members from different assemblies ? Should I just use __declspec(dllexport)
and __declspec(dllimport) or is there a different way ?
 
E

Edward Diener

Brandon said:
In 7.0, there is no way to do this. With the 7.1 compiler, the native
classes are public by default. For most people, this wasn't the
desired behavior. Hence, there is a compiler switch to make all
native types private to an assembly (at which point, there is no
solution to your problem again).

I am working with 7.1. I did use __declspec(dllexport) and
__declspec(dllimport) and a header file and it worked, but I think what you
are saying is that I need not have used that and could use #using and it
would still have worked.

It does seem as if the solution should be that __nogc classes are 'private',
just like normal non-.NET C++ classes in a DLL and:

1) One uses __declspec(dllexport) and __declspec(dllimport) and a header
file to access them
Or
2) The compiler recognizes a 'public' keyword for __nogc classes and allows
them to be exported and imported using .NET metadata just like __gc and
__value classes, and one uses #using to access them.
The type in the assembly doesn't actually have metadata (well, it has
next to no metadata). So, in order to use the type from another
assembly, a header file must say what to make of that type. #using
that type from an assembly, acts like a forward declaration for the
type.

I don't follow the above paragraph. Are you saying that if I had a #using
statement for my assembly which has __nogc classes that it would work
without needing to #include the header file ?
In Whidbey, we will allow you to write public and private on a native
class defintion.

Good idea !
 
B

Brandon Bray [MSFT]

Edward said:
I don't follow the above paragraph. Are you saying that if I had a #using
statement for my assembly which has __nogc classes that it would work
without needing to #include the header file ?

No, the #using constitutes a forward declaration. A header file is still
needed to provide the class defintion.
 
E

Edward Diener

Brandon said:
No, the #using constitutes a forward declaration. A header file is
still needed to provide the class defintion.

Was my __declspec(dllexport) for my __nogc class upon building my assembly
and __declspec(dllimport) upon using my __nogc class unneeded, therefore,
since it was by default 'public' anyway ? Which compiler switch makes the
default 'private' for __nogc classes ? If I use that switch ( or IDE
setting ), could I not then use my
__declspec(dllexport)/__declspec(dllimport) technique to make select classes
'public', so to speak while retaining the option to have all other __nogc
classes private ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top