Solved

glut/VC++4.0 difficulty

Posted on 1998-08-15
15
534 Views
Last Modified: 2012-08-14
whenever I try to use glut with openGL in my VC++4.0 compiler, the program compiles but on the linking stage I get the error

libcd.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16

can anybody tell me whats going on?
0
Comment
Question by:Booth882
  • 8
  • 7
15 Comments
 
LVL 1

Author Comment

by:Booth882
Comment Utility
Edited text of question
0
 
LVL 1

Author Comment

by:Booth882
Comment Utility
as in how I can go about resolving the unresolved external symbol _WinMain@16
0
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
Comment Utility
WinMain() is the entry point to a GUI win32 application.  Like main() is for a regular c++ application.  Did you declare a WinMain() procedure?  You must declare a WinMain(), not main() procedure..
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
WinMain() must be declared like

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
);

You can search for "WinMain" in the on-line docs to learn more about the parameters.
0
 
LVL 1

Author Comment

by:Booth882
Comment Utility
good, but what do I put as hInstance and lpCmdLine?  I have no clue
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
What do mean?  You don't call WinMain() so you don't have to supply those parameters.  Your WinMain() procedure will be called by the OS with these parameters "filled in".  Just like the "regular" main() procedure used to be called with the argc and argv parameters "filled in".

You are trying to create a windows GUI program aren't you?  If so you will have a WinMain() instead of a main().  It will take the parameters I listed above.  Look at the docs on winmain by searching for "WinMain" in the on-line help.

If you aren't trying to make a windows GUI program, you should have just a main() not a winmain().  But in that case you need a different project type.  You need a project to create a win32 console application.
0
 
LVL 1

Author Comment

by:Booth882
Comment Utility
ok heres the deal.  I have a program with a main loop, like

void main()
{
    code....
}

but when I link it I get the error above.  So as I understand you I need a WinMain() instead of a main(), which would make it

int WINAPI WinMain(hInstance, prevInstance, lpCmdLine, nCmdShow)
{
    code....
}

if that is the case, what do I put in as arguments?  I mean, what do I pass in as hInstance and prevInstance and lpCmdLine and nCmdShow?  

if that is not the case, please help me to understand what exactly it is that I need to do to get my program to link!
0
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.

 
LVL 22

Expert Comment

by:nietod
Comment Utility
first of all:

In a typical C++ program you have

int main(int argc, char * argc)
{
 code
};

Note that main returns an int, it is not void.  You can ussualy get away declaring main() as returning void, but someday you won't....

Note that main() takes two arguments.  However, you are allowed to declare main without them, like

int main()
{
  code
};

Now that is for a standard C++ program.  Microsoft and then Borland and others decided to break the rules a little.  For a windows program you don't need (actually you can't have) a main() procedure.  Instead you have a procedure called WinMain() that serves the same purpose.  But WinMain() has two differences.  First, it is named differently--that is important because this name is required and main() is not allowed.  Second, it takes a different set of parameters (Ones that you may not alter.).

Now you ask?
>> what do I pass in as hInstance and prevInstance and lpCmdLine and nCmdShow?

Well, what do you pass when you call main()?  Huh???  You don't call main().  Main is called when the program starts.  You never call it.  Same thing with WinMain().  WinMain() is called when the program starts, you don't call it.  You just put code inside WinMain() that you would have placed inside main().  Again WinMain() replaces main().
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Note that all this is true only if you are trying to create a GUI program (a "real" windows program).  If you want to create a win32 console program, then you would have an ordinary main().   A win32 console program looks like an "old fashioned" program.  That is, it displays just text, it doesn't have menus and buttons etc.

 I can't tell which you want.  But given the error you are getting, VC is trying to make a GUI program, thus, you need a WinMain().  If you want a consoel program, you cn keep your main(), but need to switch to a console project, not a GUI project.  

Thus if you still can't get it to compile, I need to know which type of program you are creating.
0
 
LVL 1

Author Comment

by:Booth882
Comment Utility
so show me how I would write it then.  is it just

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPSTR lpcmdline, int ncmdshow)
{
    code....
}

then?
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Exactly.
0
 
LVL 1

Author Comment

by:Booth882
Comment Utility
but to use glut I must call

   glutInit(int * argc, char ** argv)

which with main like

  int main(int argc, char ** argv)

I can simply go

   glutInit(& argc, argv);

my question is:  What are the WinMain equivalents to argc and argv?  are there even equivalents?  can I call such a function as glutInit using a WinMain program?
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
WinMain() gets a single parameter string, unlike main()'s nicely parsed parameter array.  Thus if you call a windows program called PROG with 3 parameters, you will get a string like
"PROG PARAM1 PARAM2 PARAM3"

You could convert this string into the data that glutinit needs. You would parse this information into an argv-like array and calculate an argc value.  (using strtok() it would be pretty easy)

However, it might not be worth it.  Since it is rare for a windows program to be called with parameters, you probably could just pass a 0 argc to glutinit indicating there are no prameters.  (I assume glutinit doesn't have to have parameters)  

I should mentuon that I am not familar with glut.  But considering the way it takes parameters, it suggests that it was not intended to be called from a true windows program.  Do you know if if can be?  What does it do?
0
 
LVL 1

Author Comment

by:Booth882
Comment Utility
perfect!  its all working.  thanks for your help once again
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Just out of curiousity--What did you do?  pass a 0 argc or did you create an argvc-like array.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

743 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

18 Experts available now in Live!

Get 1:1 Help Now