468,783 Members | 1,628 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,783 developers. It's quick & easy.

how to import STL vector to STL

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<POINTvertices) PURE;
};

Is it possible to import STL containers to C# at all?
Dec 3 '07 #1
2 2615
On Dec 3, 4:45 pm, Builder <peter.gej...@gmail.comwrote:
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<POINTvertices) 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.
Dec 3 '07 #2
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::stringstdVector;
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

*** Sent via Developersdex http://www.developersdex.com ***
Dec 4 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by {AGUT2}=IWIK= | last post: by
9 posts views Thread by luigi | last post: by
7 posts views Thread by cppaddict | last post: by
34 posts views Thread by Adam Hartshorne | last post: by
10 posts views Thread by Bob | last post: by
8 posts views Thread by Ross A. Finlayson | last post: by
16 posts views Thread by Martin Jørgensen | last post: by
6 posts views Thread by zl2k | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.