tags:

views:

78

answers:

1

How to return an array of C# strings (string[]) to unmanaged C++ code, and then use it from C++?

// Is it correct ???
[ComVisible(true)]
public string[] Foo()
{
    return new string[] {"A", "B", "C"};    
}

C++ code ??

A: 

You should define an interface to be used from the unmanaged C++ code, either as a DLL export interface, or as a COM interface. This way you can control how the strings are marshaled. (See MSDN Article on Default Marshaling)

An other way is to use C++/CLI in between, and pass your strings that way. (See C++/CLI on MSDN)

EFrank