• Advertisement
Sign in to follow this  

Need help in programming!!!!

This topic is 4329 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!!!

Share this post


Link to post
Share on other sites
Advertisement
This, boys and girls, is why you shouldn't copy-paste code from anything without understanding what it does.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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 )

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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?

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites
Quote:
Original post by superpig
This, boys and girls, is why you shouldn't copy-paste code from anything without understanding what it does.


Quoted for truth.

Anyhow, the definition of this function would look something like:

/*some variable type here*/ MyRegisterClass(HINSTANCE hInstance)
{
/*code*/
}

If you don't have that, look for it in the book's source.

Or if you do have it, make sure it is above your main() function.

Share this post


Link to post
Share on other sites
My guess is that the book you have doesn't take you through the basics and I'm going to take a wild guess and say you haven't learned the basics. You should put your book down for now, find a "Beginning programming" book, read it, understand it, then move on to your game book. It will be a lot easier to understand the game programming book and find/fix problems like the one you're having now.

Share this post


Link to post
Share on other sites
My guess is that your taking a line of code that he explains in the book and just copying that into your compiler. Harbour's book is one of the few where every project on the cd compiles without error. Until you are more comfortable with the way he does projects, use the code from the CD instead of typing it in manually. If you don't know much c++, you may want to work on that before you try to make games.

Share this post


Link to post
Share on other sites
Yeah,
I figured that out yesterday. See , the book is titled Beginning Game Programming, so I looked throught it and it seemed like a good place to start but I guess I have to get and even more beginner's book to PROGRAMMING .

thanks for the help guys

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement