What's wrong with this example

K

kimiraikkonen

I got an example from trusted cplusplus.com in order to compile and
see with Dev C++ 5, but i got a lot of "linker errors - undefined
references " or kind of that. I may give the exact source zip link but
somebody says it's illegal or not allowed in group rules, so here is
the code:
The package as winimage.cpp and winimage.h files also.

If you still accept downloading source code to investigate better,
here is the direct link:
http://www.cplusplus.com/src/wingif.zip



#include <windows.h>
#include "winimage.h"

char szAppName[]="GIF/BMP Loader Example";

LRESULT CALLBACK WndProc (HWND,UINT,WPARAM,LPARAM);

// WinMain (Windows application main function)
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;

// Register the Main Window Class:
wndclass.cbSize=sizeof (wndclass);
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon (NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor (NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH) (COLOR_WINDOW);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szAppName;
wndclass.hIconSm=LoadIcon (NULL,IDI_APPLICATION);

RegisterClassEx (&wndclass);

// Create and Show the Main Window
hwnd=CreateWindow (szAppName,szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
ShowWindow (hwnd,iCmdShow);
UpdateWindow (hwnd);

// Message Loop
while (GetMessage (&msg,NULL,0,0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}

// End Application
return msg.wParam;
}

// WndProc (Main window procedure - Message Processor)
LRESULT CALLBACK WndProc (HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM
lParam)
{
static C_Image img;
static C_ImageSet imgset;
static C_AnimationWindow anim, anim2, anim3;
switch (iMsg)
{
case WM_CREATE:
// Load Image files
img.LoadBMP ("logo.bmp");
imgset.LoadGIF ("sample.gif");
// Create 3 Animation Child Windows of the same C_ImageSet object:
// Notice how each one uses its own thread and can be
// paused independently (left-clicking)
anim.Create (hwnd,(HMENU)1000,&imgset);
anim2.Create (hwnd,(HMENU)1001,&imgset);
anim3.Create (hwnd,(HMENU)1002,&imgset);

return 0;
case WM_SIZE:
// Display and Set position of Animation Child Windows (GIF file):
anim.Display (10,10);
anim2.Display (110,10);
anim3.Display (210,10);
return 0;
case WM_PAINT:
// Paint the img object (BMP file):
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint (hwnd,&ps);
img.GDIPaint (hdc,10,100);
EndPaint (hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd,iMsg,wParam,lParam);
}




Thanks.
 
R

Rolf Magnus

kimiraikkonen said:
I got an example from trusted cplusplus.com in order to compile and
see with Dev C++ 5, but i got a lot of "linker errors - undefined
references " or kind of that.

Basically, the code uses non-standard headers, functions, types and whatnot
from beginning to end. It is off-topic here, because it's Windows specific.
Try one of the many windows programming newsgroups and ask there.
I may give the exact source zip link but somebody says it's illegal or not
allowed in group rules

Attaching files is frowned upon, but I've never heard that posting a link to
an external file was forbidden or something.
 
K

kimiraikkonen

Hi Rolf,
Which group do you recommend for authoring Windows-based C++
applications?

However, as i understood from your answer, there are some non-standard
objects, headers as you've said, so these must be installed or these
must be compiled with Visual C++ ???

Thanks
 
F

frostdrake

Hi Rolf,
Which group do you recommend for authoring Windows-based C++
applications?

However, as i understood from your answer, there are some non-standard
objects, headers as you've said, so these must be installed or these
must be compiled with Visual C++ ???

Thanks

In WinMain, it's LPSTR not PSTR, use (GetMessage(...) > 0) for message
loop condition as it can return an error code of -1 since BOOL is
defined as an int in Win32.

As for linker errors, could just be the fact you didn't give the
compiler the libraries it needs to link with, make sure under Project-
Properties it is listed as a Win32 GUI rather than Win32 Console.

I haven't checked the zip file but if both the winimage header and
source is included, there should be no problem regarding compilation.
As for headers, <windows.h> is all you need, and parsing graphic files
is only a matter of simple file i/o.
 
J

Jim Langston

kimiraikkonen said:
Hi Rolf,
Which group do you recommend for authoring Windows-based C++
applications?

microsoft.public.vc.language is a good one
However, as i understood from your answer, there are some non-standard
objects, headers as you've said, so these must be installed or these
must be compiled with Visual C++ ???

Its windows code and needs windows headers and such. VC++ would work but I
think he was just talking about it being off topic for this newsgroup
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Hi Rolf,
Which group do you recommend for authoring Windows-based C++
applications?

http://www.parashift.com/c++-faq-lite/how-to-post.html have a list of
groups a bit down.
However, as i understood from your answer, there are some non-standard
objects, headers as you've said, so these must be installed or these
must be compiled with Visual C++ ???

I think you need to download and install the Windows SDK to get windows.h.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top