cef_string_t.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. namespace Xilium.CefGlue.Interop
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. using System.Security;
  7. using System.Text;
  8. [StructLayout(LayoutKind.Sequential, Pack = libcef.ALIGN)]
  9. internal unsafe partial struct cef_string_t
  10. {
  11. internal char* _str;
  12. internal UIntPtr _length;
  13. internal IntPtr _dtor;
  14. [UnmanagedFunctionPointer(libcef.CEF_CALL)]
  15. #if !DEBUG
  16. [SuppressUnmanagedCodeSecurity]
  17. #endif
  18. public delegate void dtor_delegate(char* str);
  19. public cef_string_t(char* str, int length)
  20. {
  21. _str = str;
  22. _length = (UIntPtr)length;
  23. _dtor = IntPtr.Zero;
  24. }
  25. public static void Copy(string value, cef_string_t* str)
  26. {
  27. fixed (char* value_ptr = value)
  28. {
  29. libcef.string_set(value_ptr, value != null ? (UIntPtr)value.Length : UIntPtr.Zero, str, 1); // FIXME: do not ignore result
  30. }
  31. }
  32. public static string ToString(cef_string_t* obj)
  33. {
  34. if (obj == null) return null;
  35. return new string((char*)obj->_str, 0, (int)obj->_length);
  36. }
  37. }
  38. }