Use Marshal.SystemDefaultCharSize instead of hardcoding 2 bytes per char
Also move Marshal.FreeHGlobal up because buffer doesn't need to persist after PtrToStringAuto was called.
This commit is contained in:
parent
a3c0b05371
commit
5f158997b8
1 changed files with 2 additions and 3 deletions
|
@ -693,15 +693,14 @@ namespace OpenTK.Platform.Windows
|
||||||
{
|
{
|
||||||
// Don't forget about \0 at the end
|
// Don't forget about \0 at the end
|
||||||
uint filenameChars = Functions.DragQueryFile(hDrop, i, IntPtr.Zero, 0) + 1;
|
uint filenameChars = Functions.DragQueryFile(hDrop, i, IntPtr.Zero, 0) + 1;
|
||||||
int filenameSize = (int)(filenameChars * 2); // for unicode char set, 2 bytes per character
|
int filenameSize = (int)(filenameChars * Marshal.SystemDefaultCharSize);
|
||||||
IntPtr str = Marshal.AllocHGlobal(filenameSize);
|
IntPtr str = Marshal.AllocHGlobal(filenameSize);
|
||||||
|
|
||||||
Functions.DragQueryFile(hDrop, i, str, filenameChars);
|
Functions.DragQueryFile(hDrop, i, str, filenameChars);
|
||||||
|
|
||||||
string dropString = Marshal.PtrToStringAuto(str);
|
string dropString = Marshal.PtrToStringAuto(str);
|
||||||
OnFileDrop(dropString);
|
|
||||||
|
|
||||||
Marshal.FreeHGlobal(str);
|
Marshal.FreeHGlobal(str);
|
||||||
|
OnFileDrop(dropString);
|
||||||
}
|
}
|
||||||
|
|
||||||
Functions.DragFinish(hDrop);
|
Functions.DragFinish(hDrop);
|
||||||
|
|
Loading…
Reference in a new issue