Click to See Complete Forum and Search --> : General problems with Dev C++ and standard Windows drawing functions.


Fatboy
August 12th, 2004, 04:24 PM
I'm not experienced with Windows programming in C++, but I'm sure in this case I'm doing everything right! And there is something wrong with the Bloodshed DevC++ linker! Here is my problem:
I programmed a simple Windows application, all it does is draw a rectangle in the client area of a basic window using the Rectangle(HDC, int, int, int, int) WinApi function. However, when I try to compile it using Dev-C++, it flags a linker error (the compiler was fine, just the linker) saying:

[linker error] undefined reference to 'Rectangle@20'

What's wrong?

Thank you very much in advance.

VladimirF
August 12th, 2004, 04:36 PM
The less experienced you are, the more you are sure that you do everything right...
Did you link Gdi32.lib?

Bond
August 12th, 2004, 04:36 PM
Sounds like it's not linking with GDI32.LIB.

Try adding the following line at the top of your souce code:

#pragma comment(lib, "gdi32.lib")

Fatboy
August 13th, 2004, 05:41 AM
Thank you both very much!!!!

But I tryed Mr. Bond's method, it doesn't work........However the program works if I draw text on the main window using the DrawText() funtion, but doesn't work when I use the TextOut() function (it flags out the same linker error). DrawText() seems to be the only drawing function that works......
I managed to get hold of the Borland C++ builder 5.5 with command line tools. But it doesn't seem to be able to compile any WinApi programs! Even those which work in the Dev-C++ compiler! The borland compiler is fine, but again it's the linker. It says:

Error: Unresolved external '_main' referenced from c:\borland\bcc55\lib\c0x32.obj

What does that mean??? What's wrong?

I really appreciate your help! Thank you!!!!!!

Bond
August 13th, 2004, 08:18 AM
I still don't think you've linked properly with GDI32.LIB. That's where Rectangle() and TextOut() are located. DrawText() is in USER32.LIB, which it sounds like you're properly linked to.

The #pragma directive is dependent on the compiler. It's possible that Borland's compiler doesn't recognize #pragma comment.

As for the "main" error, are you creating a Windows application or a DOS one? Windows applications should have a WinMain, not a main.

Fatboy
August 13th, 2004, 01:34 PM
Yeah I sorted out the Borland compiler and linker, it works with Borland now. The problem was that I was creating a Windows application but the Borland linker thinks I'm creating a console one. To fix it, All I had to do is to add -W option in the command line. Thank you very much 007!

Bond
August 13th, 2004, 02:42 PM
Anytime.