i am trying to use setpixel in a forms application. i have tried many solutions but i still get error message. added some libs (gdi32, user32...), and used #include <windows.h> but none worked. firstly i was working on win32 project and it was working properly. i am using VS 2010. thanks a lot
thats the error:
error LNK2028: unresolved token (0A00000B) "extern "C" unsigned long __stdcall SetPixel(struct HDC__ *,int,int,unsigned long)" (?SetPixel@@$$J216YGKPAUHDC__@@HHK@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
....obj : error LNK2028: unresolved token (0A000010) "extern "C" struct HDC__ * __stdcall GetDC(struct HWND__ *)" (?GetDC@@$$J14YGPAUHDC__@@PAUHWND__@@@Z) referenced in function "void __clrcall `dynamic initializer for 'hdc''(void)" (???__Ehdc@@YMXXZ@?A0x3fa337bd@@$$FYMXXZ)
....obj : error LNK2019: unresolved external symbol "extern "C" unsigned long __stdcall SetPixel(struct HDC__ *,int,int,unsigned long)" (?SetPixel@@$$J216YGKPAUHDC__@@HHK@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
....obj : error LNK2019: unresolved external symbol "extern "C" struct HDC__ * __stdcall GetDC(struct HWND__ *)" (?GetDC@@$$J14YGPAUHDC__@@PAUHWND__@@@Z) referenced in function "void __clrcall `dynamic initializer for 'hdc''(void)" (???__Ehdc@@YMXXZ@?A0x3fa337bd@@$$FYMXXZ)
Ouch! Yet another person falls to VC! People don't realise how much setup work that suite does for you (It is a suite by the way, not just an IDE). How long is your code? Could you try posting it? I suspect that this is a linker error but you never know.
HDC hdc = GetDC(hWnd); // hWnd is your application handle!! do not ommit it!
SetPixel(hdc,5,5,RGB(255,0,0)); // plot a red pixel at position 5, 5
ReleaseDC (hWnd, hdc);
HDC hdc = GetDC(NULL); will get you a device-context for NOTHING...
Have you even tried GetDC(NULL)? It gets you the device context of the window that you are working on(the window that has the focus). It is also the equivalent to GetDC(HWND_DESKTOP);
Ah geomike you are correct, I did not realize you could do that, I am new to the windows programming arena so forgive me for the lack of knowledge. Perhaps I should of done a little bit of research before making myself look like an ass :/ I guess it can't be too bad, I learned something from this...
i am working on a forms application. so i dont have an identified "hwnd". i have used HWND hwnd; but it didn't work. and i need to change a pixel from desktop, can i do that if i use GetDC(hWnd)?
By the way, after i type "SetPixel(" VS doesnt show the structure COLORREF SetPixel(HDC hdc, int x, int y, COLORREF color)
like i dont have the header file. but if i type SetPixel();
it says "'SetPixel' : function does not take 0 arguments". so it has all the header files needed.
its not just about SetPixel. i have same error with GetDC and GetPixel.