Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

a c++ beginner

Posted on 1999-01-16
5
Medium Priority
?
303 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 200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

927 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