views:

152

answers:

3

Hi

I need to pass string lists to unmanaged c++ how can i do this ??

I have used IDictionary as method return type and send through com but it doesn't work How to achieve this.

i write in c# as follows

IDictionary postNames() { IDictionary post=Dictionary(); post.Add("Raj"); post.Add("Mahesh"); post.Add("john steek");

return post;
} then i have created a dll for that class contains this method.

Now how can i access these values in unmanaged c++....

I am worried about two things

1) about the return type to carry these values in c++

2) Is it possible to use like this way ..

Any Help in this regard.

Thanks in advance.

+1  A: 

A quick, dirty method is write a C++/CLI wrapper.

J-16 SDiZ
A: 

It's essentially the same problem as in this question. You can implement perfect Earwicker's answer here - declare a set of interfaces and accessor classes that wrap the Dictionary and expose them to COM.

sharptooth
I am confusing with that solution.lot of workarounds there.
Cute
A: 

Probably the simplest way is to pass a string[] and use it in the unmanaged side as an SAFEARRAY(BSTR) type. You can also pass a string[] and consume it in COM as a LPStr[] by using the MarshalAs (this is the sample on MSDN):

void FunctionCall([MarshalAs(UnmanagedType.LPARRAY, 
   ArraySubType= UnmanagedType.LPStr, SizeParamIndex=1)] 
   String [,] ar, int size );

See Default Marshaling for Arrays for more details.

Remus Rusanu