LWJGL Forum

Programming => LWJGL Documentation => Topic started by: Lobo on October 31, 2016, 21:12:21

Title: GLFW.glfwSetDropCallback
Post by: Lobo on October 31, 2016, 21:12:21
Hi,

I'm trying to use the dropCallback of GLFW


GLFW.glfwSetDropCallback(window, dropCallBack = new GLFWDropCallback()
{
@Override
public void invoke(long window, int count, long names)
{
        }
});


In the documentation I only find that "names" is a pointer to the array of UTF-8 encoded path names of the dropped files.
But I dont have any glue how to get a readable string from the long.

I dont find anything about this function in the forum.

Would be great if someone could help me.

Thanks a lot and best regards
Lobo
Title: Re: GLFW.glfwSetDropCallback
Post by: Kai on October 31, 2016, 21:46:06
This will do:

public void invoke(long window, int count, long names) {
    PointerBuffer charPointers = MemoryUtil.memPointerBuffer(names, count);
    for (int i = 0; i < count; i++) {
        String name = MemoryUtil.memUTF8(charPointers.get(i));
        System.err.println(name); // <- test: print out the path
    }
    // We MUST NOT call MemoryUtil.memFree(charPointers), because
    // the memory is managed by GLFW internally.
}
Title: Re: GLFW.glfwSetDropCallback
Post by: Lobo on November 01, 2016, 06:44:13
Perfect. Thanks a lot!
Title: Re: GLFW.glfwSetDropCallback
Post by: spasi on November 01, 2016, 08:56:12
There's also a shortcut available:

glfwSetDropCallback(window, (windowHnd, count, names) -> {
for ( int i = 0; i < count; i++ ) {
String name = GLFWDropCallback.getName(names, i);
System.err.println(name);
}
});