Last active
September 11, 2020 21:02
-
-
Save codingminecraft/5ccad3602276463388dbea349ddd18ad to your computer and use it in GitHub Desktop.
GLFW breaks windows CreateProcess function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "export.h" | |
#include <windows.h> | |
#include <stdio.h> | |
#include <iostream> | |
#include <glad/glad.h> | |
#include <GLFW/glfw3.h> | |
static GLFWwindow* window = nullptr; | |
void Stupid::Init() | |
{ | |
glfwInit(); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); | |
window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL); | |
if (window == NULL) | |
{ | |
std::cout << "Failed to create GLFW window" << std::endl; | |
glfwTerminate(); | |
return; | |
} | |
glfwMakeContextCurrent(window); | |
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) | |
{ | |
std::cout << "Failed to initialize GLAD" << std::endl; | |
return; | |
} | |
std::cout << "I'm logging from the main thread!" << std::endl; | |
} | |
void Stupid::Loop() | |
{ | |
bool started = false; | |
while (!glfwWindowShouldClose(window)) | |
{ | |
glfwSwapBuffers(window); | |
glfwPollEvents(); | |
if (!started) | |
{ | |
StartProcess(true); | |
started = true; | |
} | |
} | |
glfwTerminate(); | |
} | |
void Stupid::StartProcess(bool doIt) | |
{ | |
if (doIt) | |
{ | |
STARTUPINFOA startupInfo; | |
PROCESS_INFORMATION processInfo; | |
ZeroMemory(&startupInfo, sizeof(startupInfo)); | |
startupInfo.cb = sizeof(startupInfo); | |
ZeroMemory(&processInfo, sizeof(processInfo)); | |
// Start the program | |
bool res = CreateProcessA( | |
"C:\\Users\\Gabe\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe", // Application Name | |
(LPSTR)"-g C:\\Users\\Gabe\\Documents\\JadeProjects\\TestProject1\\scripts\\MyOtherScript.cs -r --add C:\\Users\\Gabe\\Documents\\JadeProjects\\TestProject1\\scripts", // Command Line Args | |
NULL, // Process Attributes | |
NULL, // Thread Attributes | |
FALSE, // Inherit Handles | |
DETACHED_PROCESS, // Creation Flags | |
NULL, // Environment | |
NULL, // Current Directory | |
&startupInfo, // Startup Info | |
&processInfo // Process Info | |
); | |
if (res) | |
{ | |
// Close process and thread handles | |
CloseHandle(processInfo.hProcess); | |
CloseHandle(processInfo.hThread); | |
} | |
else | |
{ | |
std::cout << "ERROR" << std::endl; | |
} | |
} | |
} | |
int main() | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#ifdef _EXPORT_DLL | |
#define DLL __declspec(dllexport) | |
#else | |
#define DLL __declspec(dllimport) | |
#endif | |
class DLL Stupid | |
{ | |
public: | |
void StartProcess(bool doIt); | |
void Init(); | |
void Loop(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "export.h" | |
int main() | |
{ | |
Stupid stupid; | |
stupid.Init(); | |
stupid.Loop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment