Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visual C++ 5 error message....I can't remember what it means!

Posted on 2001-07-24
5
Medium Priority
?
217 Views
Last Modified: 2010-04-02
I've been trying to compile this source code from a Windows program that does absolutely nothing at this point:

#include <windows.h>

LRESULT CALLBACK wndProc(HWND w,UINT msg,WPARAM wp,LPARAM lp)
{
  switch(msg) {
  case WM_CREATE:
     return 0;
  case WM_RBUTTONDOWN:
  case WM_CLOSE:
     PostQuitMessage(0);
     DestroyWindow(w);
     return 0;
  }
  return DefWindowProc(w,msg,wp,lp);
}

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
)
{
  WNDCLASS cls;
  HWND w;
  MSG msg;

  memset(&cls,0,sizeof(cls));
  cls.lpfnWndProc=wndProc;
  cls.hInstance=GetModuleHandle(0);
  cls.lpszClassName="class";
  cls.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
  RegisterClass(&cls);
  w=CreateWindowEx(0,"class","test",
     WS_POPUP|WS_VISIBLE|WS_SYSMENU|WS_CAPTION,
     5,5,200,200,0,0,cls.hInstance,0);
  while(GetMessage(&msg,0,0,0)) {
     TranslateMessage(&msg);
     DispatchMessage(&msg);
  }
}

The problem is, when I try to build this in Visual C++ 5 I get these two error messages:

Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Proj.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

What's wrong?  What I am doing wrong?  Thanks for any help! :D

0
Comment
Question by:tiffchuff
[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
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 6315666
The problem is cause by your project settings, which apparently indicate a console app as the target (for which 'main()' would be needed, whereas 'WinMain()' is mandantory for a GUI app).

Go to your project settings (Alt+F7), choose the 'Link' tab, select 'All Configurations' and take a look at the text field at the bottom. There, change '/subsystem:console' to read '/subsystem:windows'.
0
 

Expert Comment

by:westaf
ID: 6317214
For your convenience, just create a new empty win32 gui project and add your .cpp file into it and compile!
0
 
LVL 86

Expert Comment

by:jkr
ID: 6340132
tiffchuff, are you still with us?
0
 
LVL 11

Expert Comment

by:griessh
ID: 6833172
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "jkr" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6853157
Per recommendation comment force/accepted by

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

636 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