Solved

a c++ beginner

Posted on 1999-01-16
5
288 Views
Last Modified: 2010-04-02
Hello folks I'm a beginner in C++.I've been using  vc++
enterprise edition to pgm.I've been having this persistent
problems since morning so I am turning to "the experts".the prob is as follows.I have a header file & a c++ source file.I have been trying to build my proj it is creating a couple of problems. more specifically the error msg reads
inking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/String.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

OK documentation for the first one says that I have to include the function def in the header file.My question is that do I really need to do that? I have tried that but it still is giving me the same error.next Does is depend on my compiler settings. I tried changing the options but looks like even that isnt working . pl help
0
Comment
Question by:mantish
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
koskia earned 50 total points
Comment Utility
hi

actually you only have 1 error, which is you don't have a WinMain function, which is the starting point of every window program.

If you're coming from C, you are used to the main function which is the starting point, but in a window based program, some global variables must register themselves in order for the window to pop up from nowhere.

if you're trying to do a simple application which doesn't involve windows (you can make an application based on a dos 7 emulator window), you should create your project to be a win32 console application.

if you're trying to do a window program, first you have to take it one step at a time, because there's a lot to learn besides C++, and then you should make a normal win32 application (which is probably what you did and got that funny error).

remember, the error you got (if you're coming from C), is just like to have a regular C\C++ program without the main function.

int WINAPI WinMain(  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // pointer to command line
  int nCmdShow              // show state of window);

this, is the definition of the function, cut from the online help, I suggest if you're just starting off with C++, make a console application and use main().
0
 

Author Comment

by:mantish
Comment Utility
thanxs a lot koskia . That was "the" perfect answer .My program
is alive & kicking .I would really appreciate if u could give me
some more info on how to run it as a window program & what are
the vars I really need to take care of.Would the sample code u provided suffice or Do I need to add more code .once again I appreciate ur help
                   regards
                                           mantish
0
 

Expert Comment

by:koskia
Comment Utility
hey mantish
glad I've helped.
actually you need to have much more code in order to get a window start and kicking, there's alot of articles and samples on the net.
I suggest you subscribe to MSDN on msdn.microsoft.com to get the basics, or buy any win32 or MFC book on the matter.

the win32 API's are all written in C, and you can use them as they are. the Microsoft Foundation Library, which is MFC, wraps many of the system calls, and gives a C++ environment.

if you wanna see a sample code for such a basic Application, run a wizard:

File/New/Project/MFC App Wizard(EXE) ... follow the instructions and voila.
if you're new to C++, I suggest you found a good book about win32 API's (the window95/98/NT system calls), and learn the core first for better understanding of what's going on.

a good book on the subject (Only C API's with no C++ classes)
is Charles Petzold's 'Programming Windows 95' - The difinitive Developer's Guide to the Windows95 API, by Microsoft Press.

as an example from the book I can give you the most simple app:
"HelloWin.CPP" -> see my next comment down below
0
 

Expert Comment

by:koskia
Comment Utility
Actually, as I see it's a much bigger program than I've rememberred it.

read some books :)
 if you'll need any help on a specific or general issues in the future, just as, I'm here.

p.s.
The code I gave you earlier is just the very beginning of the program, in order to create a window  you need much  much more.

submit your email, and I could send you some simple apps later on the day

asaf_k@automedi.com
0
 

Author Comment

by:mantish
Comment Utility
Thanxs again for answering my question.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now