C
So dolle Sache hab mich schon total gefreut weil ich alles mit reintpret_casts irgendwie hingebogen habe:
#include "Lkhr.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
LPCWSTR szTitle = reinterpret_cast<LPCWSTR>("Hallo Welt!");
LPCWSTR szWindowClass = reinterpret_cast<LPCWSTR>("Hallo Welt!");
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
// Initialize global strings
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_APPLICATION);
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(
szWindowClass, // Name of the window class to use for this window
// we registered in MyRegisterClass
szTitle, // Title of the application
WS_OVERLAPPEDWINDOW, // Window style that Windows should make our window with
// (this is the 'default' window style for windowed apps)
20, // Starting X of the window
20, // Starting Y of the window
640, // Width of the window
480, // Height of the window
NULL, // Handle of our parent window (Null, since we have none)
NULL, // Handle to our menu (Null, since we don't have one)
hInstance, // Instance of our running application
NULL); // Pointer to window-creation data (we provide none)
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
LPCWSTR szHello = reinterpret_cast<LPCWSTR>("Hallo, liebe Leser!");
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, reinterpret_cast<int>(szHello), &rt, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Naja zu früh gefreut!
Ich zitiere(nehme lieber den CodeTag!):
1>------ Erstellen gestartet: Projekt: Win32_HALLO_WELT, Konfiguration: Debug Win32 ------
1>Kompilieren...
1>MainHelloWorld.cpp
1>Verknüpfen...
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A00001A) ""extern "C" int __stdcall EndPaint(struct HWND__ *,struct tagPAINTSTRUCT const *)" (?EndPaint@@$$J18YGHPAUHWND__@@PBUtagPAINTSTRUCT@@@Z)", auf das in Funktion ""long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A000020) ""extern "C" int __stdcall GetMessageW(struct tagMSG *,struct HWND__ *,unsigned int,unsigned int)" (?GetMessageW@@$$J216YGHPAUtagMSG@@PAUHWND__@@II@Z)", auf das in Funktion ""extern "C" int __cdecl GetMessage(struct tagMSG *,struct HWND__ *,unsigned int,unsigned int)" (?GetMessage@@$$J0YAHPAUtagMSG@@PAUHWND__@@II@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A000022) ""extern "C" void __stdcall PostQuitMessage(int)" (?PostQuitMessage@@$$J14YGXH@Z)", auf das in Funktion ""long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A000026) ""extern "C" int __stdcall DrawTextW(struct HDC__ *,wchar_t const *,int,struct tagRECT *,unsigned int)" (?DrawTextW@@$$J220YGHPAUHDC__@@PB_WHPAUtagRECT@@I@Z)", auf das in Funktion ""extern "C" int __cdecl DrawText(struct HDC__ *,wchar_t const *,int,struct tagRECT *,unsigned int)" (?DrawText@@$$J0YAHPAUHDC__@@PB_WHPAUtagRECT@@I@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A00002C) ""extern "C" struct HICON__ * __stdcall LoadCursorW(struct HINSTANCE__ *,wchar_t const *)" (?LoadCursorW@@$$J18YGPAUHICON__@@PAUHINSTANCE__@@PB_W@Z)", auf das in Funktion ""unsigned short __cdecl MyRegisterClass(struct HINSTANCE__ *)" (?MyRegisterClass@@$$FYAGPAUHINSTANCE__@@@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A000031) ""extern "C" int __stdcall GetClientRect(struct HWND__ *,struct tagRECT *)" (?GetClientRect@@$$J18YGHPAUHWND__@@PAUtagRECT@@@Z)", auf das in Funktion ""long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A000032) ""extern "C" struct HDC__ * __stdcall BeginPaint(struct HWND__ *,struct tagPAINTSTRUCT *)" (?BeginPaint@@$$J18YGPAUHDC__@@PAUHWND__@@PAUtagPAINTSTRUCT@@@Z)", auf das in Funktion ""long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A000034) ""extern "C" int __stdcall TranslateMessage(struct tagMSG const *)" (?TranslateMessage@@$$J14YGHPBUtagMSG@@@Z)", auf das in Funktion ""extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A000036) ""extern "C" unsigned short __stdcall RegisterClassExW(struct tagWNDCLASSEXW const *)" (?RegisterClassExW@@$$J14YGGPBUtagWNDCLASSEXW@@@Z)", auf das in Funktion ""unsigned short __cdecl MyRegisterClass(struct HINSTANCE__ *)" (?MyRegisterClass@@$$FYAGPAUHINSTANCE__@@@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A000037) ""extern "C" struct HICON__ * __stdcall LoadIconW(struct HINSTANCE__ *,wchar_t const *)" (?LoadIconW@@$$J18YGPAUHICON__@@PAUHINSTANCE__@@PB_W@Z)", auf das in Funktion ""unsigned short __cdecl MyRegisterClass(struct HINSTANCE__ *)" (?MyRegisterClass@@$$FYAGPAUHINSTANCE__@@@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A000044) ""extern "C" int __stdcall ShowWindow(struct HWND__ *,int)" (?ShowWindow@@$$J18YGHPAUHWND__@@H@Z)", auf das in Funktion ""int __cdecl InitInstance(struct HINSTANCE__ *,int)" (?InitInstance@@$$FYAHPAUHINSTANCE__@@H@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A00004C) ""extern "C" struct HWND__ * __stdcall CreateWindowExW(unsigned long,wchar_t const *,wchar_t const *,unsigned long,int,int,int,int,struct HWND__ *,struct HMENU__ *,struct HINSTANCE__ *,void *)" (?CreateWindowExW@@$$J248YGPAUHWND__@@KPB_W0KHHHHPAU1@PAUHMENU__@@PAUHINSTANCE__@@PAX@Z)", auf das in Funktion ""int __cdecl InitInstance(struct HINSTANCE__ *,int)" (?InitInstance@@$$FYAHPAUHINSTANCE__@@H@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A000054) ""extern "C" int __stdcall UpdateWindow(struct HWND__ *)" (?UpdateWindow@@$$J14YGHPAUHWND__@@@Z)", auf das in Funktion ""int __cdecl InitInstance(struct HINSTANCE__ *,int)" (?InitInstance@@$$FYAHPAUHINSTANCE__@@H@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A000058) ""extern "C" void * __stdcall GetStockObject(int)" (?GetStockObject@@$$J14YGPAXH@Z)", auf das in Funktion ""unsigned short __cdecl MyRegisterClass(struct HINSTANCE__ *)" (?MyRegisterClass@@$$FYAGPAUHINSTANCE__@@@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A000059) ""extern "C" long __stdcall DefWindowProcW(struct HWND__ *,unsigned int,unsigned int,long)" (?DefWindowProcW@@$$J216YGJPAUHWND__@@IIJ@Z)", auf das in Funktion ""long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2028: Nicht aufgelöstes Token (0A00005E) ""extern "C" long __stdcall DispatchMessageW(struct tagMSG const *)" (?DispatchMessageW@@$$J14YGJPBUtagMSG@@@Z)", auf das in Funktion ""extern "C" long __cdecl DispatchMessage(struct tagMSG const *)" (?DispatchMessage@@$$J0YAJPBUtagMSG@@@Z)" verwiesen wird.
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" int __stdcall GetMessageW(struct tagMSG *,struct HWND__ *,unsigned int,unsigned int)" (?GetMessageW@@$$J216YGHPAUtagMSG@@PAUHWND__@@II@Z)" in Funktion ""extern "C" int __cdecl GetMessage(struct tagMSG *,struct HWND__ *,unsigned int,unsigned int)" (?GetMessage@@$$J0YAHPAUtagMSG@@PAUHWND__@@II@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" long __stdcall DispatchMessageW(struct tagMSG const *)" (?DispatchMessageW@@$$J14YGJPBUtagMSG@@@Z)" in Funktion ""extern "C" long __cdecl DispatchMessage(struct tagMSG const *)" (?DispatchMessage@@$$J0YAJPBUtagMSG@@@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" int __stdcall DrawTextW(struct HDC__ *,wchar_t const *,int,struct tagRECT *,unsigned int)" (?DrawTextW@@$$J220YGHPAUHDC__@@PB_WHPAUtagRECT@@I@Z)" in Funktion ""extern "C" int __cdecl DrawText(struct HDC__ *,wchar_t const *,int,struct tagRECT *,unsigned int)" (?DrawText@@$$J0YAHPAUHDC__@@PB_WHPAUtagRECT@@I@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" int __stdcall UpdateWindow(struct HWND__ *)" (?UpdateWindow@@$$J14YGHPAUHWND__@@@Z)" in Funktion ""int __cdecl InitInstance(struct HINSTANCE__ *,int)" (?InitInstance@@$$FYAHPAUHINSTANCE__@@H@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" int __stdcall ShowWindow(struct HWND__ *,int)" (?ShowWindow@@$$J18YGHPAUHWND__@@H@Z)" in Funktion ""int __cdecl InitInstance(struct HINSTANCE__ *,int)" (?InitInstance@@$$FYAHPAUHINSTANCE__@@H@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" struct HWND__ * __stdcall CreateWindowExW(unsigned long,wchar_t const *,wchar_t const *,unsigned long,int,int,int,int,struct HWND__ *,struct HMENU__ *,struct HINSTANCE__ *,void *)" (?CreateWindowExW@@$$J248YGPAUHWND__@@KPB_W0KHHHHPAU1@PAUHMENU__@@PAUHINSTANCE__@@PAX@Z)" in Funktion ""int __cdecl InitInstance(struct HINSTANCE__ *,int)" (?InitInstance@@$$FYAHPAUHINSTANCE__@@H@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" long __stdcall DefWindowProcW(struct HWND__ *,unsigned int,unsigned int,long)" (?DefWindowProcW@@$$J216YGJPAUHWND__@@IIJ@Z)" in Funktion ""long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" void __stdcall PostQuitMessage(int)" (?PostQuitMessage@@$$J14YGXH@Z)" in Funktion ""long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" int __stdcall EndPaint(struct HWND__ *,struct tagPAINTSTRUCT const *)" (?EndPaint@@$$J18YGHPAUHWND__@@PBUtagPAINTSTRUCT@@@Z)" in Funktion ""long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" int __stdcall GetClientRect(struct HWND__ *,struct tagRECT *)" (?GetClientRect@@$$J18YGHPAUHWND__@@PAUtagRECT@@@Z)" in Funktion ""long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" struct HDC__ * __stdcall BeginPaint(struct HWND__ *,struct tagPAINTSTRUCT *)" (?BeginPaint@@$$J18YGPAUHDC__@@PAUHWND__@@PAUtagPAINTSTRUCT@@@Z)" in Funktion ""long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@$$FYGJPAUHWND__@@IIJ@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" unsigned short __stdcall RegisterClassExW(struct tagWNDCLASSEXW const *)" (?RegisterClassExW@@$$J14YGGPBUtagWNDCLASSEXW@@@Z)" in Funktion ""unsigned short __cdecl MyRegisterClass(struct HINSTANCE__ *)" (?MyRegisterClass@@$$FYAGPAUHINSTANCE__@@@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" void * __stdcall GetStockObject(int)" (?GetStockObject@@$$J14YGPAXH@Z)" in Funktion ""unsigned short __cdecl MyRegisterClass(struct HINSTANCE__ *)" (?MyRegisterClass@@$$FYAGPAUHINSTANCE__@@@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" struct HICON__ * __stdcall LoadCursorW(struct HINSTANCE__ *,wchar_t const *)" (?LoadCursorW@@$$J18YGPAUHICON__@@PAUHINSTANCE__@@PB_W@Z)" in Funktion ""unsigned short __cdecl MyRegisterClass(struct HINSTANCE__ *)" (?MyRegisterClass@@$$FYAGPAUHINSTANCE__@@@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" struct HICON__ * __stdcall LoadIconW(struct HINSTANCE__ *,wchar_t const *)" (?LoadIconW@@$$J18YGPAUHICON__@@PAUHINSTANCE__@@PB_W@Z)" in Funktion ""unsigned short __cdecl MyRegisterClass(struct HINSTANCE__ *)" (?MyRegisterClass@@$$FYAGPAUHINSTANCE__@@@Z)".
1>MainHelloWorld.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" int __stdcall TranslateMessage(struct tagMSG const *)" (?TranslateMessage@@$$J14YGHPBUtagMSG@@@Z)" in Funktion ""extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)".
1>C:\Dokumente und Einstellungen\GliderBugFix\Eigene Dateien\Visual Studio 2005\Projects\WinAPI\Debug\Win32_HALLO_WELT.exe : fatal error LNK1120: 32 nicht aufgelöste externe Verweise.
1>Das Buildprotokoll wurde unter "file://c:\Dokumente und Einstellungen\GliderBugFix\Eigene Dateien\Visual Studio 2005\Projects\WinAPI\Win32_HALLO_WELT\Debug\BuildLog.htm" gespeichert.
1>Win32_HALLO_WELT - 33 Fehler, 0 Warnung(en)
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
Ich tu mir echt Leid kann mir jemand vielleicht die Musterlösung für das angeblich einfachste Programm der WinAPI geben. P.S.: Das leichteste WinAPI Programm = schwerstes .NET Programm :->>>>