how to import STL vector to STL

B

Builder

How can I import the following COM interface to C#?

DECLARE_INTERFACE_(IVertices, IUnknown)
{
STDMETHOD(get_vertices) (THIS_ vector<POINT>& vertices) PURE;

STDMETHOD(set_vertices) (THIS_ vector<POINT> vertices) PURE;
};

Is it possible to import STL containers to C# at all?
 
A

Arnshea

How can I import the following COM interface to C#?

DECLARE_INTERFACE_(IVertices, IUnknown)
{
STDMETHOD(get_vertices) (THIS_ vector<POINT>& vertices) PURE;

STDMETHOD(set_vertices) (THIS_ vector<POINT> vertices) PURE;
};

Is it possible to import STL containers to C# at all?

Not that I know of. When crossing from COM to managed code you will
probably want to copy the elements from the STL container to (one or
more) arrays on the COM side, then copy from the arrays to
System.Collections (.*) on the managed side.

You'll have to tell .NET the layout of non-primitive array elements;
one way to do this is to define them in the IDL (inside the library)
so that the type library importer will automatically create managed
equivalents for you.
 
J

Jeff Louie

Builder... If you want to stick to STL you can convert a standard STL
Vector to a STL/CLI Vector in C++/CLI.

// test standard STL to STL/CLI
std::vector<std::string> stdVector;
stdVector.reserve(2);
stdVector.push_back("Hello");
stdVector.push_back("World");

vector<String^> cliVector;
cliVector.reserve(2);

std::vector<std::string>::iterator it3= stdVector.begin();
for(;it3 != stdVector.end();it3++) {
cliVector.push_back(Util::ConvertCS2MS(*it3));
}

vector<String^>::iterator it4= cliVector.begin();
for(;it4 != cliVector.end();it4++) {
Console::WriteLine(*it4);
}

Regards,
Jeff
 

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