Pass Generic::List in C++ Library to vb.net

  • Thread starter Thread starter Nip
  • Start date Start date
N

Nip

Hi
I want to access the Generic List of the following c++-class inside a vb.net
app. Is this possible/how can I do that?
Atm, I get the following error in the vb.net app: "Field 'GeoElems' is of
an unsupported type."



public ref class clsPhysik
{
......
public: System::Collections::Generic::List<GeoElem^> GeoElems;
......
}
 
My book says System::Collections::Generic classes are not CLS
compliant. So they are unsupported, with the usual caveats.

RL
 
Nip said:
Hi
I want to access the Generic List of the following c++-class inside a
vb.net app. Is this possible/how can I do that?
Atm, I get the following error in the vb.net app: "Field 'GeoElems' is of
an unsupported type."



public ref class clsPhysik
{
.....
public: System::Collections::Generic::List<GeoElem^> GeoElems;

You're using C++/CLI stack semantics, which aren't supported by any other
language. You must exposed the tracking handle. Try:

private: System::Collections::Generic::List<GeoElem^> m_GeoElems;
public: property System::Collections::Generic::List<GeoElem^>^ GeoElems {
System::Collections::Generic::List<GeoElem^>^ get() { return
%m_GeoElems; } // if compile error, try &m_GeoElems
}


Also GeoElem must be a public ref class.
 
raylopez99 said:
My book says System::Collections::Generic classes are not CLS
compliant. So they are unsupported, with the usual caveats.

I'm afraid your book is wrong, Generics are CLS compliant.

Willy.
 
The book is Pro Visual C++/CLI and the NET 2.0 Platform by Fraser, p.
196 (2006 ed.) with a foreward by Stanley Lippmann. But the note does
say that in the future Generics might become CLS compliant "Personally,
I think the CLS rules will be expanded to include generics, but we
shall see."

RL
 
Hi
Thanks a lot :)

Ben Voigt said:
You're using C++/CLI stack semantics, which aren't supported by any other
language. You must exposed the tracking handle. Try:

private: System::Collections::Generic::List<GeoElem^> m_GeoElems;
public: property System::Collections::Generic::List<GeoElem^>^ GeoElems {
System::Collections::Generic::List<GeoElem^>^ get() { return
%m_GeoElems; } // if compile error, try &m_GeoElems
}


Also GeoElem must be a public ref class.
 
raylopez99 said:
The book is Pro Visual C++/CLI and the NET 2.0 Platform by Fraser, p.
196 (2006 ed.) with a foreward by Stanley Lippmann. But the note does
say that in the future Generics might become CLS compliant "Personally,
I think the CLS rules will be expanded to include generics, but we
shall see."

Generics are available to any .NET language, the Microsoft-provided ones
as well as most 3rd party ones, such as RemObjects Chrome. That's
because generics are part of the .NET 2.0 runtime. Unlike templates,
which are compile-time constructs, generics are evaluated at runtime,
and are an integral part of the .NET 2.0 type system. In contrast,
C++/CLI templates are not accessible from other languages, and the CLS
does not know about them. Templates are replaced with non-generic
language constructs at compile time.

Reference: http://msdn2.microsoft.com/en-us/library/t357fb32.aspx

To be fair, however, the Fraser book was published very shortly after
the release of VS 2005, which implicates the author was probably using a
Beta build for the entire book, and referred to information that was
available at that time. You can't really blame him for that, and his
prediction actually came true.

Despite this small inaccuracy, the Fraser book is still a good
reference. It covers a very wide range of technology, and it turned out
to be pretty useful to me. The fact that the book was released so early
to the community far outweighs the disadvantages of those few possible
inaccuracies. You can always check the errata.

Tom
 
Thanks Tamas Demjen. I agree the Frazier book is useful, though full
of typos (but easily caught typos).

I did not know Generics were not templates (I assumed they were one and
the same). Learn something new everyday.

RL
 
Back
Top