|
MrMcIntyre wrote: I need help fixing these errors.
A book will provide you the help you need.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
MrMcIntyre wrote: I need help fixing these errors.
I agree; but you are starting from a position of ignorance, and that is not meant as an insult. As I have explained many times, you need to understand the basics before you can produce anything approaching a useful application. The code sample you put in the original question of this thread suggests that you really do not understand how to start writing a program. You seem to be taking disconnected code snippets and trying to make them work without being in a properly constructed programme.
You may not appreciate this, but I am really trying to help you, but you must also try and help yourself. Buy a book on C/C++ and also one on Windows programming. If money is an issue then go and work through some of the samples here on CodeProject, there are lots that will help you.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
MrMcIntyre wrote: 3. error C2447: '{' : missing function header (old-style formal list?)
This is the big one...
As Richard said, functions are not optional.
This is super basic stuff, which this forum is not going to be able to help you with. A beginner's book will.
If we're wrong, and you've just cut and pasted out stuff and not made a good question post, then feel free to edit.
Iain.
Edited: Typo.I have now moved to Sweden for love (awwww).
|
|
|
|
|
So no one is going to help. Andrew McIntyre
|
|
|
|
|
MrMcIntyre wrote: So no one is going to help.
I wouldn't say that. But spoonfeeding you answers only helps you this once.
OK, I'm nice. Try this:
#include <WinInet.h>
#pragma comment(lib, "wininet.lib")
void This_Is_A_Function ()
{
if (InternetGetConnectedState(INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_MODEM, 0) == FALSE)
{
MessageBox(NULL, "Sorry, no Internet Connection was detected", "iWorld", MB_OK | MB_ICONERROR);
}
}
This might help with the errors you are having... But did not help you get any further than that. If you're most of the way through writing a virtual world simulator, then surely you know how to write and call a function?
So, taking your profile as accurate, I must be misunderstanding your question?
Iain.I have now moved to Sweden for love (awwww).
|
|
|
|
|
I have got I error with the code you provided. The character that is underlined and in bold is stopping me from running the code. Please help.
void Function();
{
if (InternetGetConnectedState(INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_MODEM, 0) == FALSE)
{
MessageBox(NULL, "Sorry, no Internet Connection was detected", "iWorld", MB_OK | MB_ICONERROR);
}
}
Error:
'{' : missing function header (old-style formal list?)
Thank you very much
Andrew McIntyre
|
|
|
|
|
Take a look at the code I wrote:
void This_Is_A_Function ()
{
and the code you wrote:
void Function();
{
and the difference should become clear...
Iain.
I have now moved to Sweden for love (awwww).
|
|
|
|
|
You Don't seem to understand what 'Scope'Means. Maybe you just migrated from QBasic or so...
I'll explain this basic stuff just this once! You Start at File Scope. That's where you declare and define Golbal Variables, and Global Statics. NO ACTION CAN TAKE PLACE THERE! (except assigning Fixed Values to Variables).
Action can only take Place in a Function. Any Statement, (that is things where Action takes Place, susch as c=a+b; if(Something)doSomething(), has to take place inside a Function. A function is a Named Global Variable to which a list of Actions is attached. it is declared and may also defined in the standard way, but it is distinguished as a function because it is followed by (...)
For instance:
int A; declares a Variable of type integer, named 'A'
int A=10; does the same, but also gives it the value 10, (defines it)
int A(); declares a Function Variable Named 'A'
int A(){.....} does the same, but also defines what the function does, by the code included by the brackets. That Code is at Scope Level1 (File Scope being Level 0). This is the plase where the If, When and Whatever Code goes. (As you have in your File). The Scope level can be further increased, by nesting more {...} pairs inside it, but That's a prety advanced subject from where you are now, Save to say, You're NOT allowed to write another function inside the body of a function. (That is Different in languages susch as say Pascal). Try itin C or CPP, and you get plenty of error messages,the compiler will choke.
Functions can only be called from Other functions, and you cannot start a Function in File Scope. So, the phylosophical question arrives, 'How does it all Start'Afteral, in QBasic, it starts with the first line of Code.
That's where a Special function comes in. (Mostly) every C Program starts with a function called 'main()' Some programs start with differently named programs, and in some cases the definition of the main() program is more involved, but again, those are pretty advanced subjects from where you are now.
But, if you want to write a basic program, include all your first actions inside a function called main().
If you try this with the above snippet (I did not try it, I must admit), it will almost certainly NOT work.
The Service 'InternetGetConnectedState'requires a complicated environment around it. This again, is a very advanced subject from where you are now.
Instead of this, why don't you replace it with 'printf("Hello World");'and then build up to more difficult (and more Usefull Cases).
Unfortunately, we in the Code project cannot 'Donate'Knowledge. You have to gain it yourself, and I hope I pointed you in the right direction.
Bram van Kampen
|
|
|
|
|
Hello, first let me tell you of my basic information.
OS: Windows xp, IDE: Codeblocks 8.02, Compiler: GNU GCC Mingw32.
Let me start by saying that I've had no problem linking SDL or OpenGL by themselves, just together. The following code is at the top of the main.c file:
#include <vector>
#include <SDL/SDL.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glext.h>
the result is linker errors regarding opengl:
C:\Program Files\CodeBlocks\Source Files\simple2\main1.cpp|44|undefined reference to `_glEnable@4'|
etc., for all opengl functions. If someone can suggest how to fix it up, I'd be obliged. Thanks for your time.modified on Thursday, March 18, 2010 2:54 PM
|
|
|
|
|
bala_48225 wrote: Let me start by saying that I've had no problem linking SDL or OpenGL by themselves, just together.
In your linker settings try opengl32.lib glu32.lib before SDL libraries.
Hope it helps, I am just a guessing here.
|
|
|
|
|
that did the trick, just adding those two to the linker
|
|
|
|
|
Hi,
I have a dialog, a main dialog(MainDlg) that on press of a button creates another 12 dialogs, hidden.
All 12 dialogs hava about 20-25 controls on them and when i all Create for each of them the maindlg freezes for 1-3 seconds. I am thinking of creating a thread that creates all 12 dialogs when MainDlg begins to initialize.
So what I am doing now and it's not working. I have created a new class derived from CWinThread.
OnInitialise I have put: create(FirstDialog:IDD,g_thisParent)...g_thisParent is CWnd * pointing to 'this'. I made a function, Setup(CWnd *, Cdialog **dialogs); this is the pointer sent from OnInit of the maindlg functio.
On mainDlg ->Oninit, i have created CDialog *dialogs[12];
all dialogs are NULL and then dialogs[1]->new....(this);
anyhow: i start the thread with AfxBeginThread suspended, i call for Setup, and then I resume the thread.
I get assertion faild when I try to create using this as parent, but not when i use (CWnd*)this->GetParent wich is 0 . I don't want my dialogs to be the child of desktop window, I want them to inherit maidlg....what shall i do?
Is this a corect approach of the problem?
|
|
|
|
|
Do not create UI stuff (dialogs, controls, ...) from you secondary thread.
In you thread, you need to notify (for example using PostMessage) your main dialog to create the child dialogs.
read : http://www.flounder.com/workerthreads.htm[^]
excerpt :
"That's right. A worker thread must not touch a GUI object. This means that you should not query the state of a control, add something to a list box, set the state of a control, etc."Watched code never compiles.
|
|
|
|
|
But the problem is that I must create the dialogs at sometime.
I have a menu
Backup
Restore
shedule
whatever
backup has 12 dialogs........ if i click on backup button i must wait.
I cannot avoid the creation of those dialogs. when clicking on backup they must be created, and when i create them, each oninit function in the dialog starts from 1 to 12.
In thread everything is ok....i win a lot of time(3 seconds) and when I click on backup......i seems it instantly loads. The only problem I get is that i can't set the parent right...![Frown | :(](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_frown.gif)
|
|
|
|
|
Why do you need to create ALL your dialogs when the main dialog starts ?
Me think it's bad design to do so, only create dialogs when you need them.
Anyway, unless you are doing some weird things, creating a dialog should not take that much time.Watched code never compiles.
|
|
|
|
|
Yes indeed the design is bad, and the problem problem started from weird things. There were some variables uninitialized entering in a loop from 0 to a few milions;)) so i was suggested to use a thread to create dialogs so i got stuck on this ideea:P
the problem is, that i can jump from a dialog to another.
|
|
|
|
|
I don't think this will work as you are creating them as part of the second (temporary?) thread when you want them to be part of the main GUI thread.
Instead, since these dialogs start out hidden, why not defer their creation. Set up a wrapper to create them on first display. This distributes the work so that you don't take the full hit all at once and it should be less noticeable.
You could also set up something to create them one at a time in CWinApp::OnIdle(), though you will need to make sure they are not used until created. You could combine this with the create on first demand scheme if you want.Please do not read this signature.
|
|
|
|
|
Good point, but using UI thread it's ok, my question is why i cannot set the parrent right, I think it has something to do with sending 'this' as param in Setup function....should I sent a handle to the window instead....the problem is I don't know how, I'm new in MFC GUI;))
|
|
|
|
|
In your thread, just post a message to your main dialog with (no data) and in that message handler in your main dialog you should be able to create your dialogs without problems. Watched code never compiles.
|
|
|
|
|
After doing a little checking, evidently you can do it with child windows on a 2nd UI thread. You do have to be careful about communications between the threads since there is a possibility of creating a deadlock between the threads. I would still tend to favor using OnIdle() instead of a 2nd thread to try and deal with your performance issue.
Apart from some quibbling over precise wording, I don't see the problem with what you are doing. As far as my quibbling goes, in the parent window code you call a setup function passing "this" as a parameter so that the thread class can save its value in a member variable called g_thisParent. g_thisParent is not a pointer to "this", it is a CWnd * to the parent window object. Also, in the second thread, you never, ever use "this" in an attempt to refer to the parent window, you use the variable you have named g_thisParent.
Other than that, my only thought would be some sort of synchronization issue - but I don't see what it would be.
Please do not read this signature.
|
|
|
|
|
bu7ch3r wrote: ...that on press of a button creates another 12 dialogs...
...the maindlg freezes for 1-3 seconds.
...what shall i do?
Do not press any button to create them,
just create them all in CMainDlg::OnInitDialog() virtual void BeHappy() = 0;
|
|
|
|
|
yes, but that makes the gui start slow .
|
|
|
|
|
Place a good splash window in another thread for your start virtual void BeHappy() = 0;
|
|
|
|
|
=))))) i am creating a serious application for my university degree:P I's a good ideea anyhow![Big Grin | :-D](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_biggrin.gif)
|
|
|
|
|
How Could I Use a define macro identifier in an other define macro replacement list?
for example in the following example:
#define APP_TEST1 L"Test1"
#define APP_TEST2 L"Test2"
#define APP_TEST L"Test1 With Test2"
I want to represent the third define macro with 2 first macro?
|
|
|
|
|