How do I create an SDL console app with Visual Studio 2005?

I’m running Windows XP and I’m trying to create a console application and I’m
having a very difficult time. I have Visual Studio 2005 Pro (VC8). I’m using
VC++, not any of the .NET stuff. I’ve down loaded and built SDL.lib and
SDLmain.lib, and I can link against them. For my test program I’m using
graywin.c from the SDL distro. (I don’t care what the code does, I just want to
get a console app running.)

I did get an executable, but it didn’t do anything. (This is how I know that I
was linking correctly.) All that happened was that a blank white window popped
up, and it wouldn’t do anything. It was not a console application, it was one
of the other Windows executable types (I tried so many things that I don’t
remember which one).

My problems are not with SDL, they are with using SDL with Microsoft Studio
2005. There was a posting to this group that suggested making an empty project.
When I try to do that I get ‘Fatal Link Error LNK 1561: entry point must be
defined’. The program has a normal ‘main(int argc, char *argv[])’ function. I
think this error is because I’m trying to use a console with a blank app. If I
try and make a console application, the stub that it creates has an entry point
called ‘_tmain(int argc, _tchar *argv[])’ (or something close to that). All the
SDL docs say that I need a normal ‘main(int, char *[])’, so I don’t know what to
do about the _tmain entry point. I’ve read about SDLmain and I find it very
confusing. (I don’t really understand Windows, I’m a refugee from the Unix
world, where things make sense…)

Is there a way to use an empty project, or am I better off using a console as
generated by the IDE? If I use a console with the code stub created by Visual
Studio, what do I do about my ‘main’ entry point? When I look online for
examples, there is almost nothing about VC8, and the VC7,6,5 stuff does not
offer much guidance. At this point I spent more then a day just trying to build
my first SDL program, and I just want to get something running. I want a
cookbook solution so I can start coding. Any suggestions?

M.

Hello mwade,

Monday, August 21, 2006, 5:00:23 AM, you wrote:

I’m running Windows XP and I’m trying to create a console application and I’m
having a very difficult time. I have Visual Studio 2005 Pro (VC8). I’m using
VC++, not any of the .NET stuff. I’ve down loaded and built SDL.lib and
SDLmain.lib, and I can link against them. For my test program I’m using
graywin.c from the SDL distro. (I don’t care what the code does, I just want to
get a console app running.)

File, New->Project

Under “Visual C++” you will see “Win32”. Select that and then “Win32
Console Application”.

On the Wizard that comes up, select Next and tick “Empty Project”. You
can then make your own file with main() in it. By default, VS2005
creates a source file with a Unicode based equivalent of main() called
_tmain().

HOWEVER

For SDL, this isn’t what you want. SDL actually wants a WinMain()
entry point, but it supplies the code for this itself (in SDLmain.lib)
and then expects to call your code as main(). So, you want a Win32
Project, again, tick “Empty Project”.

There should be three build modes when you built SDL for the SDLmain
project - Debug, Release and Release_nostdio. The last one will
suppress the console window and is normally what you use for release
versions of your code.

The “White window” you describe sounds very much like the result of
creating a Win32 Project, and Visual C++ has provided you with a
template code file which by default, creates the code needed to
generate an empty window, which you would then fill in yourself. This
code is totally useless if you are working with SDL.–
Best regards,
Peter mailto:@Peter_Mulholland