• Advertisement
Sign in to follow this  

Help me!!!!

This topic is 4328 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'm learning to program using Blocks but the book I'm learning from tells me to put: //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 function Help!!!!

Share this post


Link to post
Share on other sites
Advertisement
Hey, ya know, start 9 or 10 user accounts and ask the same question. And when you get an answer, ask again anyway under a different name.

That's ridiculous, dude.

Share this post


Link to post
Share on other sites
the other guy is my friend, we r doing it together and we got stuck in the same place.

Share this post


Link to post
Share on other sites
MyRegisterClass() is not a function of the WinAPI. You have to write it. If you wrote it and you code looks like this one:

func1()
{
// here, I use MyRegisterClass()
if (!MyRegisterClass(hinstance)) { // error: MyRegisterClass is undeclared
...
}
}

bool MyRegisterClass(HINSTANCE hinstance) // MyRegisterClass definition
{
}


Then you broke one of the basic rule of C++ which is: I can't use something that hasn't been declared yet. Put the declaration of MyRegisterClass() at the top of your file and it should run:
bool MyRegisterClass(HINSTANCE hinstance); // MyRegisterClass declaration

func1()
{
// here, I use MyRegisterClass()
if (!MyRegisterClass(hinstance)) { // MyRegisterClass is declared
...
}
}

bool MyRegisterClass(HINSTANCE hinstance) // MyRegisterClass definition
{
}

HTH

Share this post


Link to post
Share on other sites
If so, then he already asked. Why ask again?

The anonymous poster in Chip Holder's thread is me. Another poster and I answered your question there.

[addendum] And thank you, Emmanuel, for explaining it in code for them. Apologies that I didn't do it, myself.

Share this post


Link to post
Share on other sites
Chip holder put the code you said on the top, and it said

ISO C++ forbids declaration of 'func1' with no type

what does that mean??

Share this post


Link to post
Share on other sites
I put in MyRegisterClass in the parantheses at the top and it says:

expected constructor, destructor, or type conversion before '(' token

can you explain please?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well, that's just an example. Try 'void func1()' if you want.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
we r going t try it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Chip Holder
by the way ,
what does that mean
void etc. etc.
That's its return type. Every function can return an int, a float, some kind of class or struct, whatever, depending on what return type you give it. If you don't need to return anything from that function, you can use void like that. That means it won't return anything; it's just a bunch of code you run inside that function.

Share this post


Link to post
Share on other sites
You know what guys...
You have really helped a lot cause now I know what I am writing and what a function is and stuff but the thing is that this book that I am reading from came with a cd and that cd was a different program that I should have been using.
I know now that this isn't working because the blocks compiler doesn't have the same library as the one the book is working off of so it dosn't recognize the functions. Right?
So I am just going to buy the book that will teach me how to use blocks and then learn from there

Thanks

Share this post


Link to post
Share on other sites
Okay, glad you know what to do. I apologize for my outburst as well. Just keep it down to one thread, okay? :P The beginners' forum has a pretty major problem with some who ask over and over without making any effort to learn; now I'm happy to know that you're not in that group.

Share this post


Link to post
Share on other sites
Quote:
Original post by Fooley
Chip holder put the code you said on the top, and it said

ISO C++ forbids declaration of 'func1' with no type

what does that mean??


No offense, but it means that you should really try to learn C/C++ before learning how to use the Windows API. The Windows API assume that you at least knows C (and I guess this is also the case of your book).

In my case, func1() was a placeholder. I don't know you code, so I can't write it. My goald was just to introduce you declaration and definition, where the role of the declaration is to tell the compiler that some entity exist (in your case, MyResgisterClass()) while the role of the definition is to implement the desired functionnality (may it be a function or a variable). The key point is that you can't use anything that hasn't been declared before (emphasis. Yeah, really). Of course, a definition also acts like a declaration, meaning that if the definition of an entity is added before its first use, everything is fine.

Really, pick up a good book about the C++ language, the kind of book that explains things - not just throw some code and explain it after, this is useless. For C++, the basic book is The C++ Programming Language, by the language creator, Bjarne Stroustrup. But the list of C++ related book is huge so you may find another book that may suit your needs - see here.

Regards,

Share this post


Link to post
Share on other sites
Hey you guys!

Just noticed your coding blocks, so I maybee can lead to a topic that helps a bit more :-)

try this

www.cprogramming.com/tutorials/lesson12.html :-)
or
www.cprogramming.com/tutorial/lesson12.html

canøt remember the link correctly! but try! :-)

Share this post


Link to post
Share on other sites
I would heartily recommend to the pair of you that you get your heads around C++ by console programming first before trying to write WinAPI stuff. The WinAPI is very hard to work with anyway and really does require a thorough understanding of the language before you can hope to make any sense of it.

I'd been doing console c and c++ for about three years before I tried to write a Win32 app from the ground up and it still took me ages to get my head round.

If you are looking for a shortcut to getting Windows apps off the ground, I'd suggest you get hold of a copy of Borland C++ Builder or something similar. The VCL will introduce you to the concepts you need to understand a lot more gently and you will have working applications a lot faster.

HTH

Paul

Share this post


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

  • Advertisement