Is there any way to get gtk_file_dialog_get_file binding working in Windows? #884
-
This might be an issue with the C library itself, or it may be that I haven't implemented the binding correctly, but when I placed these in: [DllImport("libgio-2.0.so.0", EntryPoint = "g_file_get_path")]
private static extern string LinuxGetPath(nint file);
[DllImport("libgio-2.0.0.dylib", EntryPoint = "g_file_get_path")]
private static extern string MacOSGetPath(nint file);
[DllImport("libgio-2.0-0.dll", EntryPoint = "g_file_get_path")]
private static extern string WindowsGetPath(nint file); And then called them in this: public static string GetPath(nint path)
{
if (IsLinux())
{
return LinuxGetPath(path);
}
else if (IsMacOS())
{
return MacOSGetPath(path);
}
else if (IsWindows())
{
return WindowsGetPath(path);
}
return path.ToString();
} From this: var d = FileDialog.New();
d.SetTitle(Strings.MenuOpenMP2K);
var filters = Gio.ListStore.New(FileFilter.GetGType());
filters.Append(filterGBA);
filters.Append(allFiles);
d.SetFilters(filters);
_openCallback = (source, res, data) =>
{
var fileHandle = d.OpenFinish(res, IntPtr.Zero);
if (fileHandle != IntPtr.Zero)
{
var path = FileDialog.GetPath(fileHandle);
OpenMP2KFinish(path);
d.Unref();
}
d.Unref();
};
d.Open(Handle, IntPtr.Zero, _openCallback, IntPtr.Zero); And once it reaches the GetPath method and attempts to use the DLLImport of the C library function, here's what the debugger says:
This memory allocation issue only happens in Windows. It doesn't happen on Linux distributions, because it proceeds past it without any issues and can allocate the memory just fine. So I'm really curious if this is an issue with the C library itself? Am I missing something OS-specific? Have I not implemented the GetPath method correctly? Is there any workarounds that I need to make? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
I don't know what's causing the issue, but a workaround is to make |
Beta Was this translation helpful? Give feedback.
I don't know what's causing the issue, but a workaround is to make
g_file_get_path()
return IntPtr and then get string usingMarshal.PtrToStringUTF8
https://github.com/NickvisionApps/Application/blob/windows/NickvisionApplication.GNOME/Views/MainWindow.cs#L225