first post here as I’m stuck with my wonderful C++ function.
The error I’m getting is a linker error and as follows:
main.obj : error LNK2019: unresolved external symbol "public: void thiscall controls::printText(int,int,int,int,int,char const *,struct HWND *)" (?printText@controls@@QAEXHHHHHPBDPAUHWND__@@@Z) referenced in function "long stdcall WndProc(struct HWND *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
C:\Users\HIDDEN\Documents\Visual Studio 2010\Projects\TimedShutdown\Debug\TimedShutdown.exe : fatal >error LNK1120: 1 unresolved externals
Basically I’m trying to have a class for creating win32 controls and painting text and the function to paint text is where my problem occurs.
Code is as follows:
The controls.h file segment:-
void printText( int R, int G, int B, int x, int y, LPCSTR text, HWND parent);
The controls.cpp segment
void printText(int R, int G, int B, int x, int y, LPCSTR text, HWND parent)
{
HDC hdc;
PAINTSTRUCT pss;
hdc = BeginPaint(parent, &pss);
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(R,G,B));
TextOut(hdc, 30, 20, text, strlen(text));
EndPaint(parent, &pss);
}
The main.cpp call
controls ctrls;
ctrls->printText(255,0,0,300,50,"Test text",hWnd);
I’ve removed the call and the error still occurs. Initially I was attempting to pass the HDC and PAINTSTRUCT to the function also but I’ve removed that whilst trying to identify the error source.
Im totally lost guys, im not an amazing C++ programmer but I am in the process of learning.
critisise me, I demand it!
Thanks in advance for any help given, much appreciated 🙂
You forgot to tell the compiler that the function
printTextincontrols.cppiscontrols::printText. So, it is still undefined for the compiler.Modifications you have to do in
controls.cpp:Note: The color passed to printText is probably R8G8B8, ie 8 bits per component. If I’m right, you should use
unsigned charinstead ofintforR,GandB.