Solved

a c++ beginner

Posted on 1999-01-16
5
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
koskia earned 50 total points
ID: 1184399
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
ID: 1184400
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
ID: 1184401
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
ID: 1184402
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
ID: 1184403
Thanxs again for answering my question.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

738 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