As a general rule, you use StringBuilderfor reference or return values ββand stringfor strings you don't need / need to be changed in the DLL.
StringBuilder LPTSTR, string LPCTSTR
#:
[DllImport("MyDll.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static void GetMyInfo(StringBuilder myName, out int myAge);
++:
__declspec(dllexport) void GetMyInfo(LPTSTR myName, int *age)
{
*age = 29;
_tcscpy(name, _T("Brian"));
}
# :
StringBuilder name = new StringBuilder(512);
int age;
GetMyInfo(name, out age);