Access violation when using wglChoosePixelFormatARB

I’ve been trying to write a basic Triangle program by only using the WIN32 API and OpenGL. I’ve already loaded all needed Extensions using wglGetProcAddress including wglChoosePixelFormatARB. But i keep getting a access violation exception. Here’s what i currently have:

void Core::InitializeGl()
int attributeList[19];
int versionList[5];
int pixelFormat[1];
unsigned int formatCount;

Core::deviceContext = GetDC(Core::windowHandle);

attributeList[0] = WGL_SUPPORT_OPENGL_ARB;
attributeList[1] = TRUE;
attributeList[2] = WGL_DRAW_TO_WINDOW_ARB;
attributeList[3] = TRUE;
attributeList[4] = WGL_ACCELERATION_ARB;
attributeList[6] = WGL_COLOR_BITS_ARB;
attributeList[7] = 24;
attributeList[8] = WGL_DEPTH_BITS_ARB;
attributeList[9] = 24;
attributeList[10] = WGL_DOUBLE_BUFFER_ARB;
attributeList[11] = TRUE;
attributeList[12] = WGL_SWAP_METHOD_ARB;
attributeList[13] = WGL_SWAP_EXCHANGE_ARB;
attributeList[14] = WGL_PIXEL_TYPE_ARB;
attributeList[15] = WGL_TYPE_RGBA_ARB;
attributeList[16] = WGL_STENCIL_BITS_ARB;
attributeList[17] = 8;
attributeList[18] = 0;

Core::wglChoosePixelFormatARB(Core::deviceContext, attributeList, NULL, 1, pixelFormat, &formatCount);


I’ve discovered that it is unable to read the memory for Core::deviceContext . But i don’t know why.
I am using VS19.

You loaded this with a different HWND and HDC from the ones you’re trying to use now, right? Because you can’t change the pixel format of a window after you set it.