Hello guys,
Sorry for referencing beginning of the project, but I just lost a few days try to build an simple c++ program which includes windows.h and windows functions like: GetMessage, TranslateMessage, DispatchMessage, from command prompt using cl and it won't work.
I did everything like Casey on video, but I get errors. And if I create a project in Visual Studio and put the same code in source program builds and runs just fine.
What I am missing?
Simple code from MSDN site:
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
// Register the window class.
const wchar_t CLASS_NAME[] = L"Sample Window Class";
WNDCLASS wc = {};
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// Create the window.
HWND hwnd = CreateWindowEx(
0, // Optional window styles.
CLASS_NAME, // Window class
L"Learn to Program Windows", // Window text
WS_OVERLAPPEDWINDOW, // Window style
// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, // Parent window
NULL, // Menu
hInstance, // Instance handle
NULL // Additional application data
);
if (hwnd == NULL)
{
return 0;
}
ShowWindow(hwnd, nCmdShow);
// Run the message loop.
MSG msg = {};
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
EndPaint(hwnd, &ps);
}
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
MY Errors:
W:\handmade\code>build
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
win32_handmade.cpp
Microsoft (R) Incremental Linker Version 14.00.24215.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:win32_handmade.exe
/debug
win32_handmade.obj
win32_handmade.obj : error LNK2019: unresolved external symbol __imp__GetMessage
W@16 referenced in function _wWinMain@16
win32_handmade.obj : error LNK2019: unresolved external symbol __imp__TranslateM
essage@4 referenced in function _wWinMain@16
win32_handmade.obj : error LNK2019: unresolved external symbol __imp__DispatchMe
ssageW@4 referenced in function _wWinMain@16
win32_handmade.obj : error LNK2019: unresolved external symbol __imp__DefWindowP
rocW@16 referenced in function "long __stdcall WindowProc(struct HWND__ *,unsign
ed int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
win32_handmade.obj : error LNK2019: unresolved external symbol __imp__PostQuitMe
ssage@4 referenced in function "long __stdcall WindowProc(struct HWND__ *,unsign
ed int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
win32_handmade.obj : error LNK2019: unresolved external symbol __imp__RegisterCl
assW@4 referenced in function _wWinMain@16
win32_handmade.obj : error LNK2019: unresolved external symbol __imp__CreateWind
owExW@48 referenced in function _wWinMain@16
win32_handmade.obj : error LNK2019: unresolved external symbol __imp__ShowWindow
@8 referenced in function _wWinMain@16
win32_handmade.obj : error LNK2019: unresolved external symbol __imp__BeginPaint
@8 referenced in function "long __stdcall WindowProc(struct HWND__ *,unsigned in
t,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
win32_handmade.obj : error LNK2019: unresolved external symbol __imp__EndPaint@8
referenced in function "long __stdcall WindowProc(struct HWND__ *,unsigned int,
unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
win32_handmade.obj : error LNK2019: unresolved external symbol __imp__FillRect@1
2 referenced in function "long __stdcall WindowProc(struct HWND__ *,unsigned int
,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
win32_handmade.exe : fatal error LNK1120: 11 unresolved externals