// Before calling this function please make sure that pcchAnsiStr // contains exactly the length of the string EXCLUDING null character // and that the buffer pointed by unicodeStr CONTAINS null character // otherwise this call will lead to buffer overrun and UB. internal void Convert() { if (!doConvert_) { return; } if (ansiStr_.Ptr != IntPtr.Zero) { PInvokeHelper.StringUniToAnsi(unicodeStr_.Ptr, ansiStr_.Ptr, Marshal.ReadInt32(ansiStr_.PCount) + 1); } }
public void CopyTo(IntPtr dst, StringFormat dstFormat) { // For now only Uni->Ansi conversion is needed Debug.Assert(dstFormat == StringFormat.Ansi); if (dstFormat != StringFormat.Ansi) { throw Win32Exception.Create((int)Win32Api.Error.ERROR_INVALID_PARAMETER); } if (format_ == StringFormat.Unicode) { PInvokeHelper.StringUniToAnsi(pSrcData_, dst, Length); } else { Marshal.Copy(bytes_, 0, dst, bytes_.Length); } }