dkorpel / glfw-d

D translation of GLFW, a multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input
zlib License
15 stars 7 forks source link

Win32 native access doesn't seem to build #16

Open AndrejMitrovic opened 2 years ago

AndrejMitrovic commented 2 years ago

Hi!

I've tried using apinative.d as I need access to the native window handle. But I get import errors, and also linking errors.

This patch seems to fix it:

diff --git a/source/glfw3/apinative.d b/source/glfw3/apinative.d
old mode 100644
new mode 100755
index f2c372b..d364e9d
--- a/source/glfw3/apinative.d
+++ b/source/glfw3/apinative.d
@@ -78,6 +78,8 @@ extern(C): @nogc: nothrow: __gshared: export:
  *************************************************************************/

 version (GLFW_EXPOSE_NATIVE_WIN32) {
+import glfw3.api;
+import core.sys.windows.windows;
 /** Returns the adapter device name of the specified monitor.
  *
  *  Returns: The UTF-8 encoded adapter device name (for example `\\.\DISPLAY1`)
@@ -470,4 +472,4 @@ int glfwGetOSMesaDepthBuffer(GLFWwindow* window, int* width, int* height, int* b
  *  Ingroup: native
  */
 OSMesaContext glfwGetOSMesaContext(GLFWwindow* window);
diff --git a/source/glfw3/win32_window.d b/source/glfw3/win32_window.d
old mode 100644
new mode 100755
index 2e909d4..2040409
--- a/source/glfw3/win32_window.d
+++ b/source/glfw3/win32_window.d
@@ -2133,6 +2133,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, _GLFWwindow* wind
     return err;
 }

+extern(C): @nogc: nothrow: __gshared: export:

 //////////////////////////////////////////////////////////////////////////
 //////                        GLFW native API                       //////
@@ -2142,4 +2143,4 @@ HWND glfwGetWin32Window(GLFWwindow* handle) {
     _GLFWwindow* window = cast(_GLFWwindow*) handle;
     mixin(_GLFW_REQUIRE_INIT_OR_RETURN!"null");
     return window.win32.handle;

Not sure it's the best way to do it. Let me know if you want me to PR it. Cheers~

dkorpel commented 2 years ago

Thanks for reporting, I'm on it. I've added the imports, but I'm not sure about the extra annotations. __gshared: and extern(C) should be redundant, not sure what export does, and the lack of @nogc nothrow should not be a problem when you use the prototype from apinative.d, but I'll have to look into it when I boot on Windows.

AndrejMitrovic commented 2 years ago

I think I might be mistaken about the linker issues. I thought linking failed, but it's just some strange warning:

LINK : warning LNK4217: symbol 'glfwGetWin32Window' defined in 'app.obj' is imported by 'app.obj' in function <long-mangled-name-here>
schveiguy commented 1 year ago

not sure what export does

I've run into this. export specifies on Windows that this is part of the exported DLL data symbols. If you don't include export, it won't link (for DLLs). this is not needed for functions for some reason. See e.g. I had to do this here: https://github.com/schveiguy/raylib-d/commit/6c58d346f18382cc22cf7cdd97d7965f0e2e5ba2