Tested the fixes for bug #3576125, this now should work... although there might be some cases where reading the clipboard doesn't work as supposed. I added a configuration setting, but didn't add it to the expert settings due to a lack of "space". (Did fix the spacing of the checkboxes though)

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2198 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-10-25 07:54:32 +00:00
parent cbf04192b6
commit 3e9b5b91c5
5 changed files with 57 additions and 34 deletions

View file

@ -38,8 +38,7 @@ namespace GreenshotPlugin.Core {
int size = Marshal.SizeOf(typeof(T));
ptr = Marshal.AllocHGlobal(size);
Marshal.Copy(bytes, 0, ptr, size);
object obj = Marshal.PtrToStructure(ptr, typeof(T));
return (T)obj;
return FromIntPtr<T>(ptr);
} finally {
if (ptr != IntPtr.Zero) {
Marshal.FreeHGlobal(ptr);
@ -47,6 +46,17 @@ namespace GreenshotPlugin.Core {
}
}
/// <summary>
/// Get a struct from a byte array
/// </summary>
/// <typeparam name="T">typeof struct</typeparam>
/// <param name="bytes">byte[]</param>
/// <returns>struct</returns>
public static T FromIntPtr<T>(IntPtr intPtr) where T : struct {
object obj = Marshal.PtrToStructure(intPtr, typeof(T));
return (T)obj;
}
/// <summary>
/// copy a struct to a byte array
/// </summary>
@ -59,14 +69,25 @@ namespace GreenshotPlugin.Core {
int size = Marshal.SizeOf(typeof(T));
ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(obj, ptr, true);
byte[] bytes = new byte[size];
Marshal.Copy(ptr, bytes, 0, size);
return bytes;
return FromPtrToByteArray<T>(ptr);
} finally {
if (ptr != IntPtr.Zero) {
Marshal.FreeHGlobal(ptr);
}
}
}
/// <summary>
/// copy a struct from a pointer to a byte array
/// </summary>
/// <typeparam name="T">typeof struct</typeparam>
/// <param name="ptr">IntPtr to struct</param>
/// <returns>byte[]</returns>
public static byte[] FromPtrToByteArray<T>(IntPtr ptr) where T : struct {
int size = Marshal.SizeOf(typeof(T));
byte[] bytes = new byte[size];
Marshal.Copy(ptr, bytes, 0, size);
return bytes;
}
}
}