Forms App---> SetPixel()

Dec 23, 2010 at 2:22pm
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)
Dec 23, 2010 at 6:36pm
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.
Dec 23, 2010 at 6:52pm
its just an empty project with a button. when you click the button it will do SetPixel(.....). i have also used HDC hdc=GetDC(NULL); but nothing else.
Dec 23, 2010 at 7:28pm
I found this:
http://msdn.microsoft.com/en-us/library/dd145078(VS.85).aspx

Did you also include Wingdi.h?

Could you make a list of your included files?
Dec 23, 2010 at 8:10pm
#include "stdafx.h" // empty
#include "Form1.h"
#include <Windows.h>
#include <WinGDI.h> // added but didnt work

thank you so much for your effort. but i still have the same error
Dec 24, 2010 at 12:25am
closed account (3pj6b7Xj)
2348570324987502345345???!?!? Are you kidding me?

All thats needed to plot a pixel is just...

SetPixel(device-context, x position, y position);

why is the linker making it so hard for you
Dec 24, 2010 at 12:29am
closed account (3pj6b7Xj)
Waiat you used GEtDC(NULL) !!? wrong.!!

1
2
3
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...
Dec 24, 2010 at 4:22am
closed account (LTXN8vqX)
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);
Dec 24, 2010 at 8:32am
closed account (3pj6b7Xj)
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...
Last edited on Dec 24, 2010 at 8:33am
Dec 24, 2010 at 12:47pm
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.
Last edited on Dec 24, 2010 at 5:13pm
Topic archived. No new replies allowed.