Unable to use WinAPI functions in CLR project

Hello!
I am working on a Windows Forms application using CLR. Up to now, everything has gone great, but I am trying to set a pixel in the form with the standard SetPixel() method supplied by the Windows API.
Unfortunately, whenever I try to do this, I get Error LNK2019, saying essentially that the SetPixel() function is an 'unresolved external symbol.'
This is a huge problem for me because without being able to set pixels I will not be able to even get started on the actual rendering I'm planning to do with the application.
(I'm using SetPixel() as a way of making a temporary 'graphics engine' that can draw on windows. I've made one before that worked fine (albeit painstakingly slowly), so I know I'm doing everything else perfectly. Obviously, when I start to use real graphics and rendering in my application, I'm not going to use SetPixel() but I want to be certain that Windows API functions still work, as they will be the backbone of my engine.)



Code:
(in RenderBase.h)
#ifndef RENDERBASE_H
#define RENDERBASE_H

#include <Windows.h>
class RenderBase
{
public:
void SetPixel(int x, int y, COLORREF color);
COLORREF GetPixel(int x, int y);
};

#endif


(in RenderBase.cpp)
#include "RenderBase.h"
void RenderBase::SetPixel(int _X, int _Y, COLORREF _Color)
{
HDC hDC = GetDC(GetActiveWindow());
::SetPixel(hDC, 12 + _X, 37 + _Y, _Color); //Offset the coordinates given so they show where I want them to
}

COLORREF RenderBase::GetPixel(int _X, int _Y)
{
HDC hDC = GetDC(GetActiveWindow());
return(::GetPixel(hDC, 12 + _X, 37 + _Y));
}


____
(Sorry for the bad formatting, I couldn't figure out how to get the normal code thingy working, so I had to copy it normally.)


Thank you in advance for your help!
Didi you include Gdi32.lib ?
Just tried including it, and it still doesn't compile. Still getting Error LNK2019 and the Form Designer doesn't open properly anymore.
Can you post the code of the form?

BTW. Why do you want to use the Windows GDI functions instead of the Graphics class?
Last edited on
Topic archived. No new replies allowed.