error C2065: 'hinstance': nichtdeklarierter Bezeichner
-
Hallo Zusammen ich bekomme diesen Fehler, wenn ich mein Programm compiliere:
Fehler 1 error C2065: 'hinstance': nichtdeklarierter BezeichnerDer Code ist folgdermassen:
#include "windows.h" #include <iostream> #include <stdio.h> #include <tchar.h> int _tmain(int argc, _TCHAR* argv[]) { HINSTANCE hinst; HWND hwndMain; // Create the main window. hwndMain = CreateWindowEx( 0, // no extended styles "MainWClass", // class name "Main Window", // window name WS_OVERLAPPEDWINDOW | // overlapped window WS_HSCROLL | // horizontal scroll bar WS_VSCROLL, // vertical scroll bar CW_USEDEFAULT, // default horizontal position CW_USEDEFAULT, // default vertical position CW_USEDEFAULT, // default width CW_USEDEFAULT, // default height (HWND) NULL, // no parent or owner window (HMENU) NULL, // class menu used hinstance, // instance handle NULL); // no window creation data if (!hwndMain) return FALSE; // Show the window using the flag specified by the program // that started the application, and send the application // a WM_PAINT message. ShowWindow(hwndMain, SW_SHOWDEFAULT); UpdateWindow(hwndMain); return 0; }Kann mir evtl. jemand sagen warum der Compiler hinstance nicht kennt?
Gruss
-
weil es durch WinMain und nicht durch main übergeben wird.
Mach ein Windows Programm und schreibe statt int main bzw. tmain:
int _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{code
}
-
-
Ich bin mittlerweile schon ein minimes bisschen weiter

#include "stdafx.h" #include "windows.h" #include <iostream> #include <stdio.h> #include <tchar.h> int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { HINSTANCE hinst; HWND hwndMain; // Create the main window. hwndMain = CreateWindowEx( 0, // no extended styles TEXT("MainWClass"), // class name TEXT("Main Window"), // window name WS_OVERLAPPEDWINDOW | // overlapped window WS_HSCROLL | // horizontal scroll bar WS_VSCROLL, // vertical scroll bar CW_USEDEFAULT, // default horizontal position CW_USEDEFAULT, // default vertical position CW_USEDEFAULT, // default width CW_USEDEFAULT, // default height (HWND) NULL, // no parent or owner window (HMENU) NULL, // class menu used hInstance, // instance handle NULL); // no window creation data if (!hwndMain) return FALSE; // Show the window using the flag specified by the program // that started the application, and send the application // a WM_PAINT message. ShowWindow(hwndMain, SW_SHOWDEFAULT); UpdateWindow(hwndMain); return 0; }Jetzt kommen die folgenden Fehler/Warnungen:
Warnung 1 warning C4101: 'hinst': Unreferenzierte lokale Variable
Fehler 2 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_main" in Funktion "___tmainCRTStartup". MSVCRTD.lib API_Test_
Fehler 3 fatal error LNK1120: 1 nicht aufgelöste externe Verweise.Komme irgendwie nicht weiter im Moment.
Gruss
-
Erspar dir die Fuckelei das zum Laufen zu kriegen und mach ein Win32-Project auf! Du bekommst dann eine "_tWinMain", welches der "WinMain" aus den Tutorials die man so im Internet findet entspricht.
(Der Quellcode oben soll vermutlich nur ein Teilausschnitt sein? - Zumindest registriert du dort nirgends eine Fensterklasse...)
-
Nein dies ist kein Teilausschnitt

ich möchte zuerst verstehen was die einzelnen Zeilen bedeuten, bevor ich mir einfach ein Projekt zusammenklicke.
Kennt evtl. jemand ein gutes tutorial, das mir diese Geschichte näher bringt?
Gruss
-
