Need help in programming!!!!

Started by
12 comments, last by Chip Holder 17 years, 12 months ago
I am trying to learn to program in blocks but the book that I am learning from tells me to write: // register the class MyRegisterClass(hInstance); and when I try to build it tells me : that it is undeclared and that I need to use some kind of function??????? what does this mean I copied it exactly from the book it does this for other pieces too the exact same error please help!!!
AjM&*SoG
Advertisement
This, boys and girls, is why you shouldn't copy-paste code from anything without understanding what it does.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

thanks for all your help



by the way
I didn't copy and paste it
and I don't know what it means cause I'm learning and the book teaches you after you write it.

Keep in mind that Newbs are asking the questions not seasoned pros
AjM&*SoG
What book is this?

That's a function from the code in your book, and it isn't finding it because you didn't define it when you copied all this. Don't worry, I'm sure you were just copying straight from the book. Maybe that function is in a previous example? If you want this code to compile, you'll have to define that function somewhere before you use it. If you can't find the code for it, just forget it and move on.
I would suspect that MyRegisterClass is a function defined elsewhere that wraps the windows RegisterClass or RegiserClassEx functions (which would take a WNDCLASS or WNDCLASSEX pointer).

Are you absolutely sure that the function MyRegisterClass has not been defined somewhere else in the book? It is certainly not a standard or winAPI function.
What your telling me makes sense. The book is ...
Beginning Game programming
by Jonathan s. Harbour

by thomson course technology

anyway
What do you mean that I didn't define it? How do I define it?
AjM&*SoG
I'm positive. In the last example my friend and I, did it jsut fine. We were able to make a windows window and program it to say what we wanted it to etc. But this example barely introduced MyRegisterClass

I'm looking forward into the book and it says that MyRegisterClass is passed two parameters by InitInstance so that it can set up the window class settings:

ATOM MyRegisterClass(HINSTANCE hInstance,
LPTSTR szWindowClass )
AjM&*SoG
Well that's weird. Congratulations, you found an error in the guy's book. :P

Well, have a look at RegisterClassEx. Maybe you can suit that to your needs?
Interesting because I own a copy of that book and all the Win32 code worked for me with out any compilation errors. Are you sure your typing in the code correctly? What chapter/section are you having problems in?
[See the last point first - sorry, bit slow today]

Chip, MyRegisterClass absolutely MUST be a function that the author is defining himself. I accept it is possible he forgot to put it in the book, or that it is only available on a CD or online code or something. This is becoming increasingly common in books unfortunately - they give you some of the code in the book but make you go to a website or whatever to get the rest.

When you create a window, you have to first of all fill a WNDCLASS or a WNDCLASSEX structure with information about the window's properties, then pass this structure to RegisterClass or RegisterClassEx to tell Windows about the type of window. You then create an instantiation of this type of window by passing the string you have associated with the class to the CreateWindow API call.

The author must be wrapping this up in the function MyRegisterClass function. The HINSTANCE parameter is needed for one of the fields to RegisterClass and the szWindowClass parameter would be the string associated with the class.

If the function is not detailed in the book, my advice would be to get another book. Herbert Schildt's Win32 Programming From The Ground Up is okay although there are plenty of other books that will take you through creating a window with the complete code. Alternatively, the internet is teeming with example code.

Actually, just occurred to me. You say the function takes a HINSTANCE and a LPTSTR but in your first post you are only passing the HINSTANCE. Perhaps MyRegisterClass is defined but you are calling it with the wrong parameters. If it is defined as you say in your last post, which is probably right, try calling it with

MyRegisterClass(hInstance,"myWindowClass");

and see what happens. If it works, you will need to make sure you pass "myWindowClass" or whatever you use to CreateWindow as well.

HTH

Paul

This topic is closed to new replies.

Advertisement