Solved

a c++ beginner

Posted on 1999-01-16
5
290 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
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.

910 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

15 Experts available now in Live!

Get 1:1 Help Now