glfwcreatewindow()未能在DLL的入口点中奏效

发布于 2025-01-25 12:57:12 字数 3095 浏览 2 评论 0原文

我的游戏引擎和游戏都有.dll文件。 .exe使用.dll

两个都使用glfw_mt.lib。 在dll中,有窗口类(window.cpp,window.h),我尝试到glfwcreatewindow(),但它返回null。 但是,当我在dlls主函数(entrypoint.h)中尝试时,glfwcreatewindow()工作正常。

我的窗口抽象无法创建GLFW窗口。我没有理由 entrypoint.h in dll

#include "Core.h"
#include "Game.h"
#include "Window.h"
#include "glad/glad.h"
#include "GLFW/glfw3.h"

#ifdef NK_PLATFORM_WINDOWS

#define NIKSON_START Nikson::Game* CreateGame(){return
#define NIKSON_END }
extern NIKSON_API Nikson::Game* CreateGame();
static void callback(int error_code, const char* description) {
    std::cout << "GLFW ERROR:" << error_code << " " << description << std::endl;
}
int main() 
{
    LOG("LOADED!");glfwSetErrorCallback(callback);
    if (!glfwInit())
    {
        LOG("GLFW ERROR");
    }
    
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    
    //GLFWwindow* win = glfwCreateWindow(1000, 1000, "Nikson", NULL, NULL);

    //  LOG(win)
    //
    ///*if (win==nullptr) {
    //  LOG("FAILED TO CREATE WINDOW")
    //  return 0;
    //}*/
    //glfwMakeContextCurrent(win);
    Nikson::Window* win = Nikson::CreateWindow("Nikson",1000,1000);
    std::cin.get();
    //Nikson::Game * game= CreateGame();
    ////Nikson::Window* win = new Nikson::Window();
    //game->Run();
    delete win;
}
#endif 

window.h

#pragma once
#include "Core.h"
#include "glad/glad.h"
#include "GLFW/glfw3.h"

namespace Nikson {
    struct WindowProp {
        std::string Title;
        uint32_t Width;
        uint32_t Height;
        GLFWwindow* WindowPtr;
    };
    
    class NIKSON_API Window
    {
    public:
        Window(GLFWwindow* window, const std::string& title = "Nikson",
            uint32_t width = 1600,
            uint32_t height = 900);
        void Tick();
    private:
        WindowProp m_Properities;
        
        
    };
    NIKSON_API Nikson::Window*  CreateWindow(const std::string& title = "Nikson",
        uint32_t width = 1600,
        uint32_t height = 900);
} 

window.cpp

#include "Window.h"

namespace Nikson
{
    
    Window::Window(GLFWwindow* window, const std::string& title,
        uint32_t width,
        uint32_t height)
    {
        m_Properities.Title = title;
        m_Properities.Width=width;
        m_Properities.Height=height;
        m_Properities.WindowPtr = window;
        
    }
    void Window::Tick() {
        glfwPollEvents();
    }
    Nikson::Window* CreateWindow(const std::string& title,
        uint32_t width,
        uint32_t height) 
    {
        GLFWwindow* win = glfwCreateWindow(1000,1000,"Nikson", NULL, NULL);
        if (win == NULL) {
            LOG(win)
        }
        /*if (win==nullptr) {
            LOG("FAILED TO CREATE WINDOW")
            return 0;
        }*/
        glfwMakeContextCurrent(win);
        return new Nikson::Window(win, title, width, height);
    }

}

I have .dll file with my Game Engine and .exe with game.
.exe uses .dll

Both of them use glfw_mt.lib.
In dll There is Window class (Window.cpp,Window.h) where i try to glfwCreateWindow(), but it returns NULL. HOWEVER when i try it in dlls main function (EntryPoint.h) glfwCreateWindow() works fine.

My Window abstractionm fails to create glfw window. I see no reason
EntryPoint.h in dll

#include "Core.h"
#include "Game.h"
#include "Window.h"
#include "glad/glad.h"
#include "GLFW/glfw3.h"

#ifdef NK_PLATFORM_WINDOWS

#define NIKSON_START Nikson::Game* CreateGame(){return
#define NIKSON_END }
extern NIKSON_API Nikson::Game* CreateGame();
static void callback(int error_code, const char* description) {
    std::cout << "GLFW ERROR:" << error_code << " " << description << std::endl;
}
int main() 
{
    LOG("LOADED!");glfwSetErrorCallback(callback);
    if (!glfwInit())
    {
        LOG("GLFW ERROR");
    }
    
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    
    //GLFWwindow* win = glfwCreateWindow(1000, 1000, "Nikson", NULL, NULL);

    //  LOG(win)
    //
    ///*if (win==nullptr) {
    //  LOG("FAILED TO CREATE WINDOW")
    //  return 0;
    //}*/
    //glfwMakeContextCurrent(win);
    Nikson::Window* win = Nikson::CreateWindow("Nikson",1000,1000);
    std::cin.get();
    //Nikson::Game * game= CreateGame();
    ////Nikson::Window* win = new Nikson::Window();
    //game->Run();
    delete win;
}
#endif 

Window.h

#pragma once
#include "Core.h"
#include "glad/glad.h"
#include "GLFW/glfw3.h"

namespace Nikson {
    struct WindowProp {
        std::string Title;
        uint32_t Width;
        uint32_t Height;
        GLFWwindow* WindowPtr;
    };
    
    class NIKSON_API Window
    {
    public:
        Window(GLFWwindow* window, const std::string& title = "Nikson",
            uint32_t width = 1600,
            uint32_t height = 900);
        void Tick();
    private:
        WindowProp m_Properities;
        
        
    };
    NIKSON_API Nikson::Window*  CreateWindow(const std::string& title = "Nikson",
        uint32_t width = 1600,
        uint32_t height = 900);
} 

Window.cpp

#include "Window.h"

namespace Nikson
{
    
    Window::Window(GLFWwindow* window, const std::string& title,
        uint32_t width,
        uint32_t height)
    {
        m_Properities.Title = title;
        m_Properities.Width=width;
        m_Properities.Height=height;
        m_Properities.WindowPtr = window;
        
    }
    void Window::Tick() {
        glfwPollEvents();
    }
    Nikson::Window* CreateWindow(const std::string& title,
        uint32_t width,
        uint32_t height) 
    {
        GLFWwindow* win = glfwCreateWindow(1000,1000,"Nikson", NULL, NULL);
        if (win == NULL) {
            LOG(win)
        }
        /*if (win==nullptr) {
            LOG("FAILED TO CREATE WINDOW")
            return 0;
        }*/
        glfwMakeContextCurrent(win);
        return new Nikson::Window(win, title, width, height);
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文