public string GetDlgItemText(int nID) { unsafe { int textLength = (int)User32APIs.GetDlgItemTextW(Hwnd, nID, new IntPtr(0), 0); byte[] textBuffer = new byte[(textLength + 1) * 2]; fixed(byte *textBufferPtr = textBuffer) { User32APIs.GetDlgItemTextW(Hwnd, nID, new IntPtr(textBufferPtr), textLength + 1); } return(Encoding.Unicode.GetString(textBuffer, 0, textLength * 2)); } }