Archived

This topic is now archived and is closed to further replies.

Why wont it work?

This topic is 5648 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

There''s got to be something wrong with my copy of VC++, nothing works, not even the simplest codes will work, even if I set all preferences right and all. It always complains about some error in some of the include files. How come there are errors in the standard include files??

Share this post


Link to post
Share on other sites
there are like hundreds of errors in different include files, most of them aren''t even used in my code, and I''ve set everything up correctly, I''m sure of that. I don''t understand it...

Share this post


Link to post
Share on other sites
I have a constructive idea. Why don''t you try to not include the same include file multiple times. For example if you include windows.h, don''t include any other windows related headers unless they are not included in windows.h. If your lazy, you can try the obsolete "#pragma once" (without the quotes) definition.

Share this post


Link to post
Share on other sites
We can't really help you unless you say what errors you get (if there are alot of similar errors, don't post them all, a sample will probably do).

What code have you tested with?
Does the following compile?

    
#include <iostream>


using namespace std; // thanks to the people below for pointing this out.


int main()
{
cout << "Hello World!" << endl;
}

[EDIT: I fixed the "using namespace std"-thing. It completely slipped my mind, sorry about that. I compiled the code under gcc 2.95.3, and since it compiled and ran fine I didn't think that I had forgotten anything ]

[edited by - Dactylos on June 24, 2002 10:33:29 AM]

Share this post


Link to post
Share on other sites
Ok, none of the above worked (but that might be simply because I suck at C++). Here''s a sample that should initialize DirectDraw, that doesn''t work for me (but then again, I suck ass at programming, which might be the reason):





#include <ddraw.h>
// globals (ugh)
LPDIRECTDRAW lpDD; // DirectDraw object defined in DDRAW.H

/*
* Function to initialize DirectDraw
* Demonstrates:
* 1) Creating the Direct Draw Object
* 2) Setting the Cooperative level
* 3) Setting the Display mode
*
*/
bool DirectDrawInit(HWND hwnd)
{
HRESULT ddrval;

/*
* Create the main DirectDraw object.
*
* This function takes care of initializing COM and Constructing
* the DirectDraw object.
*/
ddrval = DirectDrawCreate( NULL, &lpDD, NULL );
if( ddrval != DD_OK )
{
return(false);
}

/*
* The cooperative level determines how much control we have over the
* screen. This must at least be either DDSCL_EXCLUSIVE or DDSCL_NORMAL
*
* DDSCL_EXCLUSIVE allows us to change video modes, and requires
* the DDSCL_FULLSCREEN flag, which will cause the window to take over
* the fullscreen. This is the preferred DirectDraw mode because it allows
* us to have control of the whole screen without regard for GDI.
*
* DDSCL_NORMAL is used to allow the DirectDraw app to run windowed.
*/
ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN );
if( ddrval != DD_OK )
{
lpDD->Release();
return(false);
}

/*
* Set the video mode to 640x480x8
* This is allowed because we have set exclusive mode above
*/
ddrval = lpDD->SetDisplayMode( 640, 480, 8);
if( ddrval != DD_OK )
{
lpDD->Release();
return(false);
}

return(true);
}






And these are the errors I get:


--------------------Configuration: init - Win32 Debug--------------------
Linking...
init.obj : error LNK2001: unresolved external symbol _DirectDrawCreate@12
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/init.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

init.exe - 3 error(s), 0 warning(s)






There are no errors when compiling, just linking.

Share this post


Link to post
Share on other sites
You get that error because you are using a "win32 console application" as the project type instead of "win32 application". You selected this when you started a new project.

Really, I can only recommend that you forget all about DirectX before you feel comfortable with programming in C++ in general. You will break your neck if you try to walk before you can crawl.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
That code shouldn''t compile, Dactyl. Because there''s no "using namespace std;"

Share this post


Link to post
Share on other sites
please...learn to program before you try to learn to program directX. You said that you suck *** at programming then I highly recommend that you learn to program before you go fooling around with DirectX.

and your first error is because you didnt link with the ddraw.lib and the second error is because of 2 reasons. First you created a Console application which cant be used for direct draw and second, in a console application you MUST have a main function and the compiler cant find it.


"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T

Share this post


Link to post
Share on other sites
AP is right. Dactylos'' code should not compile as it is. What compiler are you using? Aparently your
< iostream > 
is including
using namespace std; 
, which it should NOT be doing.

As far as the whole DirectX thing is concerned, I totally agree with felonius and ncsu121978. If you''re (by your own admission) not any good at programming, how the @#$%@$ do you expect to learn DirectX? I''m not trying to be rude here, just realistic.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/

Share this post


Link to post
Share on other sites
Well I''m a newbie too, but personally, I think you learn a lot more by figuring out things for yourself, and using the board as a last resort. I mean, anyone can initialize Direct Draw with minimum programming knowledge (copy and paste, anyone?), but not everyone can understand what they''re doing. To be a skilled programmer, it''s not just important to know HOW to do something, but WHY it works, IMHO.

So in response to the starter of this thread, lay off the DirectX for a bit and learn some basic C++. Trust me, from someone who was recently in your position, it will be better for you in the end. You''ll only get frustrated otherwise.

Share this post


Link to post
Share on other sites
Thanks people for pointing out the mistake in my code. How embarrassing when I''m trying to give fool-proof code and everything . Anyway, I''ve updated the code so future newbies reading this post won''t be mislead. (btw, in case you''re interested, the compiler I tested it on was gcc 2.95.3).

Share this post


Link to post
Share on other sites
pretty sure you cant use DirectX with gcc FYI
incase you are still wanting to do DirectX soon

"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T

Share this post


Link to post
Share on other sites
quote:
Original post by ncsu121978
pretty sure you cant use DirectX with gcc FYI
incase you are still wanting to do DirectX soon

Yes you can. Just remember to compile with -fvtable-thunks to make the v-tables gcc generates compatible with COM.
Anyway, didn''t he say he was using MSVC++?

Share this post


Link to post
Share on other sites