My code that i'm making to grab a pixel on the screen and gets it's color seems to have a memory issue somewhere at the line std::cout << "("; there is a segmentation fault occuring i'm new to c++ so i'm not sure why this is happening any help in debugging would be helpful, thank you. Here is my code:
#include <iostream>
#include <windows.h>
int main() {
try {
HDC dng = GetDC(NULL);
if (dng) {
COLORREF c = GetPixel(dng, 1920 / 2, 1080 / 2);
std::cout << "(";
// std::cout << (int)GetRValue(c) << ", ";
// std::cout << (int)GetGValue(c) << ", ";
// std::cout << (int)GetBValue(c) << ")";
ReleaseDC(NULL, dng);
} else {
std::cout << "Null found!";
}
} catch (const std::exception& e) {
std::cerr << "Exception: " << e.what() << std::endl;
}
return 0;
}
This is the only code in my whole project besides the .vscode settings