When using Marshal.PtrToStringUni to try and get a string from the incoming
pointer, the string just contains garble. And when i try and write to the
pointer using Marshal.StringToCoTaskMemUni, the data is not correctly
written, since the c++ client has some kind of error (can't see the error
though).
public interface MyInterface
{
[PreserveSig]
int Validate([MarshalAs(UnmanagedType.LPWStr)] string PathName, ref IntPtr
Answers);
//The c++ interface definition:
//HRESULT Validate([in, string] wchar_t* PathName,[in, out, unique, string]
wchar_t** Answers);
}
public class ComServer : MyInterface
{
public ComServer()
{
}
public int Validate(string Pathname, ref IntPtr Answers)
{
string temp;
temp = Marshal.PtrToStringUni(Answers);
ValidatorForm VF = new ValidatorForm();
VF.PromptData.Text = CK_and_Dest_Pathname + "\n\r\n\r\n\r" + temp;
//Get some text to send back through 'Answers'
VF.ShowDialog();
Marshal.FreeCoTaskMem(Answers);
//Get text to send back
string str = VF.PromptAnswer;
Answers = Marshal.StringToCoTaskMemUni(str);
}