473,387 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to access std::vector in C Sharp

I have created a COM server in which a collection of vectors need to
be exposed to C# sharp client .

Each vector contains a array of structures and this vector need to be
embedded inside a container, say another vector or list.

Code:
typedef struct
{
std::string name;
std::string type;

} STAGE_INFO;

std::vector<STAGE_INFO m_stages;

m_stages.push_back(current_stage)

Since STL classes are not accessible in C#, I used a SAFEARRAY and
VARIANT for exposing them. But I am not successful because of the
following reason .

1) I am not able to create a VARIANT array of structures.
2) I created a SAFEARRAY of structures and included it in a VARIANT,
but when accessed in C# as Object, I am not able to get the structure.
Though I am able to typecast it into a Object array , but if accessed
in separte gives exception.
3) I am able to access the members of the structure as they are string
but not a STRUCTURE as a whole.
4) I tried containing a VARIANT of SAFEARRAY'S in another VARIANT, but
it gives a casting error.
5) CComVariant cannot have USD's and VARIANT if used has some problem
of Memory Leaks.

Please let me know if you have expertise in COM and C#.Net
Interoperability.
or
Even if you have some alternate solution for this problem?

Thanks In Advance .. expecting your earliest reply.
_________________
Life Rocks,

$dhanu's$

Oct 2 '07 #1
2 7015
Try asking in:

microsoft.public.donet.languages.vc

--
Cholo Lennon
Bs.As.
ARG
<Dh*********@gmail.comwrote in message
news:11*********************@50g2000hsm.googlegrou ps.com...
I have created a COM server in which a collection of vectors need to
be exposed to C# sharp client .

Each vector contains a array of structures and this vector need to be
embedded inside a container, say another vector or list.

Code:
typedef struct
{
std::string name;
std::string type;

} STAGE_INFO;

std::vector<STAGE_INFO m_stages;

m_stages.push_back(current_stage)

Since STL classes are not accessible in C#, I used a SAFEARRAY and
VARIANT for exposing them. But I am not successful because of the
following reason .

1) I am not able to create a VARIANT array of structures.
2) I created a SAFEARRAY of structures and included it in a VARIANT,
but when accessed in C# as Object, I am not able to get the structure.
Though I am able to typecast it into a Object array , but if accessed
in separte gives exception.
3) I am able to access the members of the structure as they are string
but not a STRUCTURE as a whole.
4) I tried containing a VARIANT of SAFEARRAY'S in another VARIANT, but
it gives a casting error.
5) CComVariant cannot have USD's and VARIANT if used has some problem
of Memory Leaks.

Please let me know if you have expertise in COM and C#.Net
Interoperability.
or
Even if you have some alternate solution for this problem?

Thanks In Advance .. expecting your earliest reply.
_________________
Life Rocks,

$dhanu's$

Oct 2 '07 #2
See inline:

<Dh*********@gmail.comwrote in message
news:11*********************@50g2000hsm.googlegrou ps.com...
>I have created a COM server in which a collection of vectors need to
be exposed to C# sharp client .

Each vector contains a array of structures and this vector need to be
embedded inside a container, say another vector or list.

Code:
typedef struct
{
std::string name;
std::string type;

} STAGE_INFO;

std::vector<STAGE_INFO m_stages;

m_stages.push_back(current_stage)

Since STL classes are not accessible in C#, I used a SAFEARRAY and
VARIANT for exposing them. But I am not successful because of the
following reason .

1) I am not able to create a VARIANT array of structures.
Well, you are, but you have to export the structure through COM. For
this, you are better off defining the structure in your type library with
the following IDL:

[uuid(81FE33F8-1F84-47e4-97BF-24B0C29278B4)]
struct PriceFeedSheetInstrumentKeyColumn
{
BSTR Name;
BSTR Type;
};

You will want to change the GUID in the uuid attribute. When you change
the IDL this way, the compiler should pick up on it and generate the header
files/structure declarations that you can place into a SAFEARRAY and marshal
through COM.

You will then want to use these structures when passing them outside of
your COM object.
2) I created a SAFEARRAY of structures and included it in a VARIANT,
but when accessed in C# as Object, I am not able to get the structure.
Though I am able to typecast it into a Object array , but if accessed
in separte gives exception.
Did you define the structure in C#? If so, how?
3) I am able to access the members of the structure as they are string
but not a STRUCTURE as a whole.
How are you doing this? You indicate that you are not able to get the
structure above, if you can't get the structure, then how are you getting
the members of it.
4) I tried containing a VARIANT of SAFEARRAY'S in another VARIANT, but
it gives a casting error.
5) CComVariant cannot have USD's and VARIANT if used has some problem
of Memory Leaks.
Using variants is just going to give you one layer of indirection that
you don't need.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
>
Please let me know if you have expertise in COM and C#.Net
Interoperability.
or
Even if you have some alternate solution for this problem?

Thanks In Advance .. expecting your earliest reply.
_________________
Life Rocks,

$dhanu's$

Oct 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Jason Heyes | last post by:
To my understanding, std::vector does not use reference counting to avoid the overhead of copying and initialisation. Where can I get a reference counted implementation of std::vector? Thanks.
18
by: Janina Kramer | last post by:
hi ng, i'm working on a multiplayer game for a variable number of players and on the client side, i'm using a std::vector<CPlayer> to store informatik about the players. CPlayer is a class that...
5
by: Eric Lilja | last post by:
Hello, consider this complete program (sorry, it's not minimal but I hope it's readable at least): #include <algorithm> #include <iostream> #include <vector> class Row { public:
20
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
32
by: zl2k | last post by:
hi, c++ user Suppose I constructed a large array and put it in the std::vector in a function and now I want to return it back to where the function is called. I can do like this: ...
56
by: Peter Olcott | last post by:
I am trying to refer to the same std::vector in a class by two different names, I tried a union, and I tried a reference, I can't seem to get the syntax right. Can anyone please help? Thanks
6
by: lokchan | last post by:
i want to create a vector of pointer s.t. it can handle new and delete but also have std::vector interface can i implement by partial specialization and inherence like follow ? #include...
8
by: Lionel B | last post by:
On my platform I find that the std::vector<boolspecialisation incurs a significant performance hit in some circumstances (when compared, say, to std::vector<intprogrammed analagously). Is it...
13
by: jubelbrus | last post by:
Hi I'm trying to do the following. #include <vector> #include <boost/thread/mutex.hpp> #include <boost/shared_ptr.hpp> #include <boost/tuple/tuple.hpp> class {
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.