Linker error (_main)
-
Hallo,
hoffe ich bin mit meiner Frage hier an der richtigen Stelle. Ich bin gerade dabei mir C++ beizubringen indem ich alte Programme von Delphi versuche nach C++ (VC++ Autorenversion) zu portieren, leider stehe ich erst ganz am Anfang. Hier nun der Code + Linker-meldung:#include <windows.h> { hdc = BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps); return(0); } break; case WM_DESTROY: { PostQuitMessage(0); return(0); } break; default: break; } return(DefWindowProc(hwnd,msg,wparam,lparam)); } int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX winclass; HWND hwnd; MSG msg; //Fenstereigenschaften festlegen: winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = WINDOW_CLASS_NAME; winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); hinstance_app = hinstance; if(!RegisterClassEx(&winclass)) return(0); if(!(hwnd = CreateWindowEx(NULL,WINDOW_CLASS_NAME,"MEIN PROGRAMM", WS_POPUP | WS_VISIBLE, 0,0, 1024,768,NULL,NULL, hinstance, NULL))) return(0); main_window_handle = hwnd; while(TRUE) { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if(msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } //Programm_Hauptschleife(); } return(msg.wParam); }Hier der Linkererror[beim erzeugen der Exe] (beim Kompilieren erhalte ich keine Fehler):
LIBCD.lib(crt0.obj) : error LNK2001: Nichtaufgeloestes externes Symbol _main
Debug/main.exe : fatal error LNK1120: 1 unaufgeloeste externe Verweise
Fehler beim Ausführen von link.exe.Hoffe mir kann jmd. helfen
Lurnon
-
Falscher Projekttyp - du hast ein WinAPI-Programm (WinMain()) als Konsolenprogramm angelegt (letzteres benötigt die main() als Startpunkt).
-
Irgendwie ist oben ein wenig Code verloren gegangen,
das muss zwischen der 1. und der dritten Zeile stehen:#define WINDOW_CLASS_NAME "Shell Window" HWND main_window_handle = NULL; HINSTANCE hinstance_app = NULL; LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; HDC hdc; //Nachrichtenverarbeitung switch(msg) //case of { case WM_CREATE: { return(0); } break; case WM_PAINT:
-
Vielen Dank für die schnelle Hilfe, es geht jetzt tadellos!