# Compatibility, when creating window from DLL

**URL:** <https://discourse.glfw.org/t/compatibility-when-creating-window-from-dll/2451>\
**Category:** support\
**Created:** [September 15, 2023, 9:34am UTC](https://discourse.glfw.org/t/compatibility-when-creating-window-from-dll/2451 "2023-09-15T09:34:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bugblatterbeast](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bugblatterbeast](https://discourse.glfw.org/u/bugblatterbeast)\
**Post date:** [September 15, 2023, 9:34am UTC](https://discourse.glfw.org/t/compatibility-when-creating-window-from-dll/2451/1 "2023-09-15T09:34:43Z")

</div>

I have an old application with an internal 3D view that is implemented with a viewer library (dll) in C. Now this library shall also be able to open an external window and show an additional 3D view on another screen. With GLFW I manage to open another window but I can’t draw the content. It seems as if the OpenGL legacy functions are disabled.

I can clear and swap the buffer, but the OpenGL V1.4 functions like glBegin(GL\_TRIANGLES) doesn’t seem to work.

Additionally, once I create a window using GLFW, I seem to lose access to the existing internal OpenGL-Plane that was initialized with wgl. I can’t update the internal view anymore.

I appended this to the header:

```auto
...
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
extern GLFWwindow* ExtWindow;

```

source:

```auto
// many includes ...
GLFWwindow* ExtWindow = NULL;
...
createExtWindow() {
  glfwInit();
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
  ExtWindow = glfwCreateWindow(600, 400, "Test Window", NULL, NULL);
}

extWindowLegacyTest() {
  glfwMakeContextCurrent(ExtWindow);
  glClearColor(0, 0, 0, 0);
  glClear(GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT);
  // draw basic triangle with glBegin() is not working
  glFlush();
  glfwSwapBuffer(ExtWindow);
}

```

EDIT: added a few more details to the source code.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [September 15, 2023, 3:23pm UTC](https://discourse.glfw.org/t/compatibility-when-creating-window-from-dll/2451/2 "2023-09-15T15:23:31Z")

</div>

There are a number of examples in GLFW which use the legacy OpenGL API, so I recommend you try these first, for example take a look at [boing.c](https://github.com/glfw/glfw/blob/3eaf1255b29fdf5c2895856c7be7d7185ef2b241/examples/boing.c).

It’s likely that the reason the `wgl` window OpenGL functions no longer work is because the context for that window is not current.

---

<div class="post-metadata">

**Author:** ![bugblatterbeast](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bugblatterbeast](https://discourse.glfw.org/u/bugblatterbeast)\
**Post date:** [September 15, 2023, 4:04pm UTC](https://discourse.glfw.org/t/compatibility-when-creating-window-from-dll/2451/3 "2023-09-15T16:04:42Z")

</div>

Thanks a lot, Doug.

I will take a very close look at the example.

Regarding the wgl panel:  
When I’m trying to make that context current like I used to, it doesn’t work.

```auto
wglMakeCurrent(hDeviceContext, hRenderingContext);

```

I’ve also thought about this:

```auto
GLFWwindow* MainWindow = NULL;
// after initializing wgl Window, before initializing glfw:
MainWindow = glfwGetCurrentContext();
glfwMakeContextCurrent(MainWindow);

```

But it doesn’t work either. glfwGetCurrentContext returns NULL when wgl context is current.

---

<div class="post-metadata">

**Author:** ![bugblatterbeast](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bugblatterbeast](https://discourse.glfw.org/u/bugblatterbeast)\
**Post date:** [September 17, 2023, 11:57am UTC](https://discourse.glfw.org/t/compatibility-when-creating-window-from-dll/2451/4 "2023-09-17T11:57:12Z")

</div>

It turned out, that I didn’t see the actual problem. I assumed it was a problem with those legacy functions that this old library is using, but I was wrong. It was just that I haven’t set up the DisplayPort correctly (silly me). That was the reason why glClear seemed to work but content didn’t show.

I didn’t manage to find a better solution to the problem that I was losing access to the OpenGL-Plane that was initialized with wgl, so I’ve decided to use GLFW only to create the window and then create the OpenGL context for that window with wgl as well.

```auto
createExtWindow() {
  glfwInit();
  glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
  ExtWindow = glfwCreateWindow(600, 400, "Test View", NULL, NULL);
  HWND hWindow2 = glfwGetWin32Window(ExtWindow);
  // initialize OpenGL context using wgl
  ...
}

```

This solution worked for me to solve both issues. It’s probably not recommendable for new projects but I think it was the least effort to add a new feature to this old project.
