simple programs angering anti-virus - c++

Why do simple old programs like this that I've had lying around for years sometimes set off my anti-virus? It picked up the compiled exe for this one and said it might be a gen/dropper or something like that.
Here's the code:
#include "c:\\dxsdk\\include\\d3d9.h"
#include "c:\\dxsdk\\include\\d3dx9.h"
#include <time.h>
#include <sstream>
using namespace std;
#define APPTITLE "DirectX Practice"
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);
int Initialize(HWND);
void OnCleanup(HWND);
void OnInterval(HWND);
BOOL KEY_DOWN(UINT);
BOOL KEY_UP(UINT);
LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;
LPDIRECT3DSURFACE9 backBuffer = NULL;
LPDIRECT3DSURFACE9 surface = NULL;
UINT Screen_Width = 0;
UINT Screen_Height = 0;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
//
MSG msg;
////////////
Screen_Width = 1280;//GetSystemMetrics(SM_CXFULLSCREEN);
Screen_Height= 800;//GetSystemMetrics(SM_CYFULLSCREEN);
// can't use the real rez if it isn't standard
if( Screen_Width==0 || Screen_Height==0 ){
MessageBox(
NULL,
"Could not detect native screen resolution. Using Default.",
"Error",
MB_ICONERROR|MB_SYSTEMMODAL);
Screen_Width = 800;
Screen_Height = 600;
}
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_BTNFACE);
wc.lpszMenuName = NULL;
wc.lpszClassName = APPTITLE;
wc.hIconSm = NULL;
if(!RegisterClassEx(&wc))
return FALSE;
HWND hwnd;
hwnd = CreateWindow(
APPTITLE,
APPTITLE,
WS_EX_TOPMOST|WS_VISIBLE|WS_POPUP,
CW_USEDEFAULT,
CW_USEDEFAULT,
Screen_Width,
Screen_Height,
NULL,
NULL,
hInstance,
NULL);
if(!hwnd)
return FALSE;
ShowWindow(hwnd,SW_SHOW/*nCmdShow*/);
UpdateWindow(hwnd);
if(!Initialize(hwnd))
return FALSE;
int done = 0;
while( !done )
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message==WM_QUIT)
{
MessageBox(hwnd,"Exiting","Notice",MB_OK|MB_SYSTEMMODAL);
done = 1;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}else{
OnInterval(hwnd);
}
}
return msg.wParam;
}
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
OnCleanup(hwnd);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
return 0;
}
int Initialize(HWND hwnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
if(d3d == NULL){
MessageBox(hwnd,"Could not initialize Direct3D 9","Error",MB_ICONERROR|MB_SYSTEMMODAL);
return 0;
}
D3DPRESENT_PARAMETERS dp;
ZeroMemory(&dp,sizeof(dp));
dp.Windowed = FALSE;
dp.SwapEffect = D3DSWAPEFFECT_DISCARD;
dp.BackBufferFormat = D3DFMT_X8R8G8B8;
dp.BackBufferCount = 1;
dp.BackBufferWidth = Screen_Width;
dp.BackBufferHeight = Screen_Height;
dp.hDeviceWindow = hwnd;
d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&dp,
&d3ddev);
if(d3ddev == NULL){
MessageBox(hwnd,"Could not create Direct3D 9 device","Error",MB_ICONERROR|MB_SYSTEMMODAL);
return 0;
}
srand(time(NULL));
d3ddev->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);
d3ddev->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&backBuffer);
if(d3ddev->CreateOffscreenPlainSurface(
1294,614,
D3DFMT_X8R8G8B8,
D3DPOOL_DEFAULT,
&surface,
NULL) != D3D_OK )
{
MessageBox(hwnd,"Could not create off-screen data surface","Error",MB_ICONERROR|MB_SYSTEMMODAL);
return 0;
}
if(D3DXLoadSurfaceFromFile(
surface,
NULL,
NULL,
"green.jpg",
NULL,
D3DX_DEFAULT,
0,
NULL) != D3D_OK )
{
MessageBox(hwnd,"Could not load image","Error",0);
return 0;
}
return 1;
}
void OnCleanup(HWND hwnd)
{
MessageBox(hwnd,"exiting","bye",MB_ICONERROR|MB_SYSTEMMODAL);
if( surface!=NULL )
{
surface->Release();
}
if(d3ddev!=NULL)
{
d3ddev->Release();
}
if(d3d!=NULL)
{
d3d->Release();
}
}
void OnInterval(HWND hwnd)
{
/*RECT rect;
int r;
int g;
int b;
*/
if( KEY_DOWN(VK_ESCAPE) )
PostMessage(hwnd,WM_QUIT,0,0);
if(d3ddev == NULL)
return;
d3ddev->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);
if(d3ddev->BeginScene())
{
/*r = rand()%255;
g = rand()%255;
b = rand()%255;
d3ddev->ColorFill(surface,NULL,D3DCOLOR_XRGB(r,g,b));
rect.left = rand()%Screen_Width/2;
rect.top = rand()%Screen_Height/2;
rect.right = rect.left + rand()%Screen_Width/2;
rect.bottom = rect.top + rand()%Screen_Height/2;
*/
// blit surface's contents to the screen into the
// target rect area
d3ddev->StretchRect(surface,NULL,backBuffer,&rect,D3DTEXF_NONE);
d3ddev->EndScene();
}
d3ddev->Present(NULL,NULL,NULL,NULL);
}
BOOL KEY_DOWN(UINT key)
{
return (BOOL)(GetAsyncKeyState(key) & 0x8000);
}
BOOL KEY_UP(UINT key)
{
return !((BOOL)(GetAsyncKeyState(key) & 0x8000));
}
What is setting off the virus scanner, and more precisely, what can I do to avoid that?

Check what happens when you recompile. If it the problem does not persist then it might be that some other process is tampering with your executable. Check why the virri scanner matches what pattern in your file and if your compiler really created that code (by dumping intermediate assembler of the compiler)
Hope that helps

I think it's a trend. There are only so much viruses an antivirus software can detect. So they started detecting a lot of false positives to remind the user how good the antivirus is and how lucky he is his computer was protected.
I also encounter this problem very often. Some users start complaining about false positives with an antivirus, I submit a report, an update is issued fixing the false positive and in a month the false positive is back.
The best solution is a digital signature. A digitally signed file comes with a guarantee that it's from a trusted source, so most antivirus applications don't report it as a problem. The downside is that you have to buy a code signing certificate.

Related

DirectX 11 engine is not running suddenly after third code improvement and I don't know why

I am Following a C++ game tutorial using the DirectX 11 engine. In the first two parts, my code was fine, but on the third part (creating the SwapChain) the DirectX window decided to not show up, leaving me with the console. I don't really know how to describe the code so I will just insert all the classes, header files, etc.
main.cpp:
#include "AppWindow.h"
int main()
{
AppWindow app;
if (app.Init())
{
while (app.isRun())
{
app.brodcast();
}
}
return 0;
}
AppWindow.cpp:
#include "AppWindow.h"
void AppWindow::onCreate()
{
GraphicsEngine::get()->init();
m_swap_chain = GraphicsEngine::get()->crreateSwapChain();
RECT rc = this->getClientWindowRect();
m_swap_chain->init(this->m_hwnd, rc.right-rc.left, rc.bottom-rc.top);
}
void AppWindow::onUpdate()
{
}
void AppWindow::onDestroy()
{
Window::onDestroy();
GraphicsEngine::get()->release();
}
AppWindow.h:
#pragma once
#include "Window.h"
#include "GraphicsEngine.h"
#include "SwapChain.h"
class AppWindow: public Window
{
public:
// Inherited via Window
virtual void onCreate() override;
virtual void onUpdate() override;
virtual void onDestroy() override;
private:
SwapChain * m_swap_chain;
};
Window.cpp:
#include "Window.h"
Window* window = nullptr;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg)
{
case WM_CREATE:
{
//Event fired when the window will be created
//collected here...
Window* window = (Window*)((LPCREATESTRUCT)lparam)->lpCreateParams;
//...and then stored here for later look up
SetWindowLongPtr(hwnd, GWL_USERDATA, (LONG_PTR)window);
window->setHWND(hwnd);
window->onCreate();
break;
}
case WM_DESTROY:
{
//Event fired when the window will be destroyed
window->onDestroy();
::PostQuitMessage(0);
break;
}
default:
return ::DefWindowProc(hwnd, msg, wparam, lparam);
}
return NULL;
}
bool Window::Init()
{
WNDCLASSEX wc;
wc.cbClsExtra = NULL;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = NULL;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = NULL;
wc.lpszClassName = "MyWindowClass";
wc.lpszMenuName = "";
wc.style = NULL;
wc.lpfnWndProc = &WndProc;
if (!::RegisterClassEx(&wc)) //if the registration of the class will fail, the function will return false
return false;
if (!window)
window = this;
//creation of the window
m_hwnd=::CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, "MyWindowClass", "DirectX Application", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768, NULL, NULL, NULL, NULL);
//if the creation fails then the method will return false
if (!m_hwnd)
return false;
//show up the window
::ShowWindow(m_hwnd, SW_SHOW);
::UpdateWindow(m_hwnd);
//set this flag to true to indicate that the window is initialized and running
m_is_run = true;
return true;
}
bool Window::brodcast()
{
MSG msg;
while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
window->onUpdate();
Sleep(0);
return true;
}
bool Window::Release()
{
//destroy the window
if (!::DestroyWindow(m_hwnd))
return false;
return true;
}
void Window::onDestroy()
{
m_is_run = false;
}
bool Window::isRun()
{
return m_is_run;
}
RECT Window::getClientWindowRect()
{
RECT rc;
::GetClientRect(this->m_hwnd, &rc);
return rc;
}
void Window::setHWND(HWND hwnd)
{
this->m_hwnd = hwnd;
}
Window.h:
#pragma once
#include <windows.h>
class Window
{
public:
//Initialize the window
bool Init();
bool brodcast();
//Release the window
bool Release();
bool isRun();
RECT getClientWindowRect();
void setHWND(HWND hwnd);
//EVENTS
virtual void onCreate()=0;
virtual void onUpdate()=0;
virtual void onDestroy()=0;
protected:
HWND m_hwnd;
bool m_is_run;
};
GraphicsEngine.cpp:
#include "GraphicsEngine.h"
#include <d3d11.h>
#include "SwapChain.h"
bool GraphicsEngine::init()
{
D3D_DRIVER_TYPE driver_types[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE
};
UINT num_driver_types = ARRAYSIZE(driver_types);
D3D_FEATURE_LEVEL feature_levels[]=
{
D3D_FEATURE_LEVEL_11_0
};
UINT num_feature_levels = ARRAYSIZE(feature_levels);
HRESULT res = 0;
for (UINT driver_type_index = 0; driver_type_index < num_driver_types;)
{
res = D3D11CreateDevice(NULL, driver_types[driver_type_index], NULL, NULL, feature_levels,
num_feature_levels, D3D10_1_SDK_VERSION, &m_d3d_device, &m_feature_level, &m_imm_context);
if (SUCCEEDED(res))
break;
++driver_type_index;
}
if (FAILED(res))
{
return false;
}
m_d3d_device->QueryInterface(__uuidof(IDXGIDevice), (void**)&m_dxgi_device);
m_dxgi_device->GetParent(__uuidof(IDXGIAdapter), (void**)&m_dxgi_adapter);
m_dxgi_adapter->GetParent(__uuidof(IDXGIFactory), (void**)&m_dxgi_factory);
return true;
}
bool GraphicsEngine::release()
{
m_dxgi_device->Release();
m_dxgi_adapter->Release();
m_dxgi_factory->Release();
m_imm_context->Release();
m_d3d_device->Release();
return true;
}
GraphicsEngine * GraphicsEngine::get()
{
static GraphicsEngine engine;
return &engine;
}
SwapChain * GraphicsEngine::crreateSwapChain()
{
return new SwapChain();
}
GraphicsEngine.h
#pragma once
#include <d3d11.h>
class SwapChain;
class GraphicsEngine
{
public:
//initialize graphics engine and DirectX 11 device
bool init();
//release all the resources loaded
bool release();
static GraphicsEngine* get();
SwapChain* crreateSwapChain();
private:
ID3D11Device * m_d3d_device;
D3D_FEATURE_LEVEL m_feature_level;
ID3D11DeviceContext * m_imm_context;
IDXGIDevice * m_dxgi_device;
IDXGIAdapter * m_dxgi_adapter;
IDXGIFactory * m_dxgi_factory;
friend class SwapChain;
};
SwapChain.cpp:
#include "SwapChain.h"
#include "GraphicsEngine.h"
bool SwapChain::init(HWND hwnd, UINT width, UINT height)
{
ID3D11Device *device = GraphicsEngine::get()->m_d3d_device;
DXGI_SWAP_CHAIN_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.BufferCount = 1;
desc.BufferDesc.Width = width;
desc.BufferDesc.Height = height;
desc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc.BufferDesc.RefreshRate.Numerator = 60;
desc.BufferDesc.RefreshRate.Denominator = 1;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.OutputWindow = hwnd;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Windowed = TRUE;
//Create the SwapChain for the window initialized by the HWND paramater
HRESULT hr = GraphicsEngine::get()->m_dxgi_factory->CreateSwapChain(device, &desc, &m_swap_chain);
if (FAILED(hr))
{
return false;
}
return true;
}
bool SwapChain::release()
{
m_swap_chain->Release();
delete this;
return true;
}
SwapChain.h:
#pragma once
#include <d3d11.h>
class SwapChain
{
public:
//Initialize a SwapChain for a window
bool init(HWND hwnd, UINT width, UINT height);
//release the SwapChain
bool release();
private:
IDXGISwapChain* m_swap_chain;
};
In window.cpp I get an Exception at this->m_hwnd = hwnd;
The problem is in this line of code:
Window* window = (Window*)((LPCREATESTRUCT)lparam)->lpCreateParams;
The incoming lparam is a null value, making window a null pointer, which eventually leads to an access error.
How to solve?
When call CreateWindowEx, you need to pass a pointer to Window class in the final void* parameter.
//creation of the window
m_hwnd = ::CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, "MyWindowClass", "DirectX Application", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768, NULL, NULL, NULL, window);
Note: (Problems you may encounter)
If the Direct3D 11.1 runtime is present on the computer and
pFeatureLevels is set to NULL, this function won't create a
D3D_FEATURE_LEVEL_11_1 device. To create a D3D_FEATURE_LEVEL_11_1
device, you must explicitly provide a D3D_FEATURE_LEVEL array that
includes D3D_FEATURE_LEVEL_11_1. If you provide a D3D_FEATURE_LEVEL
array that contains D3D_FEATURE_LEVEL_11_1 on a computer that doesn't
have the Direct3D 11.1 runtime installed, this function immediately
fails with E_INVALIDARG.
Refer: D3D11CreateDevice function
You may need to use D3D11_SDK_VERSION instead of D3D10_1_SDK_VERSION in D3D11CreateDevice.
Refer: How To: Get the Device Feature Level

How can I draw correctly in a window with Direct2D?

I was making a program that draws two lines and a circle in the window, for this I used Direct2D.
I was doing a program that draws two lines and a circle in the window. I noticed a problem and that is that when drawing a line of coordinates (100,200), (200,200), that line is not drawn in the pixels (100,200) and ( 200,200). I checked this by reading the coordinates of the mouse in the window and seeing if the line actually has the coordinates that I mentioned.
Do a little more research, and according to Microsoft, direct2d works with dpi and not physical pixels.
So is there a way to work directly with pixels like in Processing or Win32 where the position of the controls is expressed in physical pixels of the window.
#include <d2d1_3.h>
#include <d2d1_3helper.h>
#include <d3d11_1.h>
#include <dxgi1_6.h>
#include <string>
#pragma comment(lib,"d3d11")
#pragma comment(lib,"d2d1")
#pragma comment(lib,"dxgi")
#pragma warning(disable : 4996)
using namespace D2D1;
using namespace std;
template<typename Interface> void SafeRelease(Interface**);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInst
, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) {
UNREFERENCED_PARAMETER(hPrevInst);
UNREFERENCED_PARAMETER(lpCmdLine);
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINLOGO));
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = L"Demo_Wnd_Class";
wc.lpszMenuName = NULL;
wc.style = 0;
RegisterClass(&wc);
DWORD dwTopLevelWndStyle = WS_OVERLAPPEDWINDOW ^ (WS_THICKFRAME | WS_MAXIMIZEBOX);
RECT clientRc = { 0,0,640,480 };
AdjustWindowRect(&clientRc, dwTopLevelWndStyle, FALSE);
HWND hWnd = CreateWindow(L"Demo_Wnd_Class", L"Direct2DDemo", dwTopLevelWndStyle, CW_USEDEFAULT, CW_USEDEFAULT
, clientRc.right - clientRc.left, clientRc.bottom - clientRc.top, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, SW_SHOWDEFAULT);
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
ID3D11Device* d3dDevice;
IDXGIDevice* dxgiDevice = NULL;
D3D_FEATURE_LEVEL featureLevels[] = {
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1,
};
HRESULT hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_BGRA_SUPPORT, featureLevels
, 7, D3D11_SDK_VERSION, &d3dDevice, NULL, NULL);
if (SUCCEEDED(hr)) {
OutputDebugString(L"D3D11 Device created successful\n");
hr = d3dDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice);
}
ID2D1Device6* d2dDevice = NULL;
ID2D1DeviceContext6* d2dDeviceContext = NULL;
IDXGIFactory2* dxgiFactory = NULL;
IDXGISwapChain1* dxgiSwapChain = NULL;
IDXGISurface *dxgiBackBufferSurface = NULL; // Back buffer
ID2D1Bitmap1* bmpTarget = NULL;
ID2D1SolidColorBrush* shapeBr = NULL;
DXGI_SWAP_CHAIN_DESC1 dscd;
dscd.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
dscd.BufferCount = 2;
dscd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
dscd.Flags = 0;
dscd.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
dscd.Height = 480;
dscd.SampleDesc.Count = 1;
dscd.SampleDesc.Quality = 0;
dscd.Scaling = DXGI_SCALING_NONE;
dscd.Stereo = FALSE;
dscd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
dscd.Width = 640;
if (SUCCEEDED(hr)) {
OutputDebugString(L"DXGI Device created successful\n");
hr = D2D1CreateDevice(dxgiDevice, CreationProperties(D2D1_THREADING_MODE_SINGLE_THREADED, D2D1_DEBUG_LEVEL_NONE, D2D1_DEVICE_CONTEXT_OPTIONS_NONE), (ID2D1Device**)&d2dDevice);
}
if (SUCCEEDED(hr)) {
OutputDebugString(L"D2D Device created successful\n");
hr = d2dDevice->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_NONE, (ID2D1DeviceContext**)&d2dDeviceContext);
}
if (SUCCEEDED(hr)) {
OutputDebugString(L"D2D Device Context created successful\n");
hr = CreateDXGIFactory2(DXGI_CREATE_FACTORY_DEBUG, __uuidof(IDXGIFactory2), (void**)&dxgiFactory);
}
if (SUCCEEDED(hr)) {
OutputDebugString(L"DXGI Factory created successful\n");
hr = dxgiFactory->CreateSwapChainForHwnd(d3dDevice, hWnd, &dscd, NULL, NULL, &dxgiSwapChain);
}
if (SUCCEEDED(hr)) {
OutputDebugString(L"DXGI Swap Chain created successful\n");
hr = dxgiSwapChain->GetBuffer(0, __uuidof(IDXGISurface), (void**)&dxgiBackBufferSurface);
}
if (SUCCEEDED(hr)) {
hr = d2dDeviceContext->CreateBitmapFromDxgiSurface(dxgiBackBufferSurface, BitmapProperties1(D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW, PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE),0,0), &bmpTarget);
}
if (SUCCEEDED(hr)) {
OutputDebugString(L"D2D Bitmap created successful\n");
d2dDeviceContext->SetTarget(bmpTarget);
hr = d2dDeviceContext->CreateSolidColorBrush(ColorF(ColorF::White), &shapeBr);
}
if (SUCCEEDED(hr)) {
OutputDebugString(L"D2D Solid Color Brush created successful\n");
d2dDeviceContext->SetUnitMode(D2D1_UNIT_MODE_PIXELS);
d2dDeviceContext->SetTransform(Matrix3x2F::Identity());
d2dDeviceContext->SetAntialiasMode(D2D1_ANTIALIAS_MODE::D2D1_ANTIALIAS_MODE_ALIASED);
}
while (msg.message != WM_QUIT) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else {
d2dDeviceContext->BeginDraw();
d2dDeviceContext->Clear(ColorF(ColorF::ForestGreen));
d2dDeviceContext->DrawLine(Point2F(400, 0), Point2F(400, 400), shapeBr);
d2dDeviceContext->DrawLine(Point2F(200.0f, 320.0f), Point2F(400.0f, 320.0f), shapeBr);
d2dDeviceContext->DrawEllipse(D2D1::Ellipse(Point2F(300.0f, 300.0f), 10.0f, 10.0f), shapeBr);
POINT cursorPos;
GetCursorPos(&cursorPos);
ScreenToClient(hWnd,&cursorPos);
wstring dbgCursorPos = wstring(L"(MouseX: " + to_wstring(cursorPos.x) + L" MouseY: " + to_wstring(cursorPos.y) + L")\n");
OutputDebugString(dbgCursorPos.c_str());
d2dDeviceContext->EndDraw();
dxgiSwapChain->Present(1, 0);
}
}
SafeRelease(&d3dDevice);
SafeRelease(&dxgiBackBufferSurface);
SafeRelease(&dxgiDevice);
SafeRelease(&dxgiFactory);
SafeRelease(&dxgiSwapChain);
SafeRelease(&d2dDevice);
SafeRelease(&d2dDeviceContext);
SafeRelease(&bmpTarget);
SafeRelease(&shapeBr);
return 0;
}
template<typename Interface> void SafeRelease(Interface** ppInterface) {
if (*ppInterface) {
(*ppInterface)->Release();
(*ppInterface) = NULL;
}
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
if (Msg == WM_DESTROY) {
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}

VS 2013 errorC3861 PeekMessage etc and errorC2065 WNDCLASSEX

I am attempting a new user graphics tutorial but I am very stuck. I am a very new programmer...I was under the impression that most of these definitions would be included in I included. My message handler is missing an identifier 'DefWindowProcess', WINDCLASSEX is also not being identified, GetModuleHandle function, PeekMessage/TranslateMessage etc. The Microsoft dev center says that all these definitions should be in windows.h.
#ifndef _SYSTEMCLASS_H_
#define _SYSTEMCLASS_H_
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "inputclass.h"
#include "graphicsclass.h"
class SystemClass
{
public:
SystemClass();
SystemClass(const SystemClass&);
~SystemClass();
bool Initialize();
void Shutdown();
void Run();
LRESULT CALLBACK MessageHandler(HWND, UINT, WPARAM, LPARAM);
private:
bool Frame();
void InitializeWindows(int&, int&);
void ShutdownWindows();
private:
LPCWSTR m_applicationName;
HINSTANCE m_hinstance;
HWND m_hwnd;
InputClass* m_Input;
GraphicsClass* m_Graphics;
};
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static SystemClass* ApplicationHandle = 0;
#endif
my systemclass.cpp is as follows
#include "pch.h"
#include "systemclass.h"
SystemClass::SystemClass()
{
m_Input = 0;
m_Graphics = 0;
}
bool SystemClass::Initialize()
{
int screenWidth, screenHeight;
bool result;
screenWidth = 0;
screenHeight = 0;
// Initialize the windows api.
InitializeWindows(screenWidth, screenHeight);
m_Input = new InputClass;
if (!m_Input)
{
return false;
}
// Initialize the input object.
m_Input->Initialize();
// Create the graphics object. This object will handle rendering all the graphics for this application.
m_Graphics = new GraphicsClass;
if (!m_Graphics)
{
return false;
}
// Initialize the graphics object.
result = m_Graphics->Initialize(screenWidth, screenHeight, m_hwnd);
if (!result)
{
return false;
}
return true;
}
void SystemClass::Shutdown()
{
// Release the graphics object.
if (m_Graphics)
{
m_Graphics->Shutdown();
delete m_Graphics;
m_Graphics = 0;
}
// Release the input object.
if (m_Input)
{
delete m_Input;
m_Input = 0;
}
// Shutdown the window.
ShutdownWindows();
return;
}
void SystemClass::Run()
{
MSG msg;
bool done, result;
// Initialize the message structure.
ZeroMemory(&msg, sizeof(MSG));
// Loop until there is a quit message from the window or the user.
done = false;
while (!done)
{
// Handle the windows messages.
if ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// If windows signals to end the application then exit out.
if (msg.message == WM_QUIT)
{
done = true;
}
else
{
// Otherwise do the frame processing.
result = Frame();
if (!result)
{
done = true;
}
}
}
return;
}
bool SystemClass::Frame()
{
bool result;
// Check if the user pressed escape and wants to exit the application.
if (m_Input->IsKeyDown(VK_ESCAPE))
{
return false;
}
// Do the frame processing for the graphics object.
result = m_Graphics->Frame();
if (!result)
{
return false;
}
return true;
}
LRESULT CALLBACK SystemClass::MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam)
{
switch (umsg)
{
// Check if a key has been pressed on the keyboard.
case WM_KEYDOWN:
{
m_Input->KeyDown((unsigned int)wparam);
return 0;
}
// Check if a key has been released on the keyboard.
case WM_KEYUP:
{
m_Input->KeyUp((unsigned int)wparam);
return 0;
}
default:
{
return DefWindowProc(hwnd, umsg, wparam, lparam);
}
}
}
void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
{
WNDCLASSEX wc; //THIS IS THE PROBLEM
DEVMODE dmScreenSettings;
int posX, posY;
// Get an external pointer to this object.
ApplicationHandle = this;
// Get the instance of this application.
m_hinstance = GetModuleHandle(NULL);
// Give the application a name.
m_applicationName = L"Engine";
// Setup the windows class with default settings.
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = m_hinstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hIconSm = wc.hIcon;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = m_applicationName;
wc.cbSize = sizeof(WNDCLASSEX);
// Register the window class.
RegisterClassEx(&wc);
// Determine the resolution of the clients desktop screen.
screenWidth = GetSystemMetrics(SM_CXSCREEN);
screenHeight = GetSystemMetrics(SM_CYSCREEN);
if (FULL_SCREEN)
{
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = (unsigned long)screenWidth;
dmScreenSettings.dmPelsHeight = (unsigned long)screenHeight;
dmScreenSettings.dmBitsPerPel = 32;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
// Change the display settings to full screen.
ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
// Set the position of the window to the top left corner.
posX = posY = 0;
}
else
{
// If windowed then set it to 800x600 resolution.
screenWidth = 800;
screenHeight = 600;
// Place the window in the middle of the screen.
posX = (GetSystemMetrics(SM_CXSCREEN) - screenWidth) / 2;
posY = (GetSystemMetrics(SM_CYSCREEN) - screenHeight) / 2;
}
// Create the window with the screen settings and get the handle to it.
m_hwnd = CreateWindowEx(WS_EX_APPWINDOW, m_applicationName, m_applicationName,
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP,
posX, posY, screenWidth, screenHeight, NULL, NULL, m_hinstance, NULL);
// Bring the window up on the screen and set it as main focus.
ShowWindow(m_hwnd, SW_SHOW);
SetForegroundWindow(m_hwnd);
SetFocus(m_hwnd);
// Hide the mouse cursor.
ShowCursor(false);
return;
}
void SystemClass::ShutdownWindows()
{
// Show the mouse cursor.
ShowCursor(true);
// Fix the display settings if leaving full screen mode.
if (FULL_SCREEN)
{
ChangeDisplaySettings(NULL, 0);
}
// Remove the window.
DestroyWindow(m_hwnd);
m_hwnd = NULL;
// Remove the application instance.
UnregisterClass(m_applicationName, m_hinstance);
m_hinstance = NULL;
// Release the pointer to this class.
ApplicationHandle = NULL;
return;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam)
{
switch (umessage)
{
// Check if the window is being destroyed.
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
// Check if the window is being closed.
case WM_CLOSE:
{
PostQuitMessage(0);
return 0;
}
// All other messages pass to the message handler in the system class.
default:
{
return ApplicationHandle->MessageHandler(hwnd, umessage, wparam, lparam);
}
}
}
Figured it out, directx projects don't recognize window API, I needed a win32 project, apply #stdafx headers on all my cpp files to get precompiled headers to work an also add #pragma once to all header files to avoid pch errors. VS is a bit quirky it turns out. Also for all the other noobs, make sure you set up file paths for directx and that you add files through project ->add->newfile->appropriate file type. it will save you headaches from VS knowing correct file locations.

Windows has triggered a breakpoint in my Thread

In my application I'm loading (for example) Device_Manager.dll and this Device_Manager depend on the selected model start to load the correct Devices.dll.
In my Device_Manager.dll, I created a window to use its handle later on my Devices because Devices uses this handle when they want to send messages to the application.
So, I made the new thread in my Device_Manager.dll to get these message when ever they arrive!
(I'm also using QT for create/load .dlls.)
After I created a thread, I received this error:
Windows has triggered a breakpoint in sepanta.agent.exe.
This may be due to a corruption of the heap, which indicates a bug in sepanta.agent.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while sepanta.agent.exe has focus.
The output window may have more diagnostic information.
I use these two methods to initialize and start my device manager:
(These methods are called in the main application after I successfully load the .dll.)
bool DeviceManagerPlugin::initializeDeviceManager()
{
EventManager pEventManager = new EventManager();
bool init_result = pEventManager->initilize_window();
...
if(initilize_status == S_OK)
{
return true;
}
else
{
return false;
}
}
void DeviceManagerPlugin::startDeviceManager()
{
handle_of_thread = 0;
int data_of_thread = 1;
handle_of_thread = CreateThread(NULL, 0,listenToIncomingWFSMessages2, &data_of_thread, 0, NULL);
my_thread_handle = handle_of_thread;
}
This is my EventManager class, which created windows:
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
...
default:
return DefWindowProc(hWnd, msg, wParam, lParam );
}
}
bool EventManager::initialize_window()
{
WNDCLASS Wclass;
HWND gHwnd = NULL;
HINSTANCE gHinstance = NULL;
ZeroMemory(&Wclass, sizeof(WNDCLASS));
Wclass.hInstance = gHinstance;
Wclass.cbClsExtra = 0;
Wclass.cbWndExtra = 0;
Wclass.lpszClassName = TEXT("Device_Manager_Class_Name");
Wclass.lpszMenuName = NULL;
Wclass.lpfnWndProc = WndProc;
Wclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
Wclass.hCursor = LoadIcon(NULL, IDC_ARROW);
Wclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
Wclass.style = CS_OWNDC;
if(!RegisterClass(&Wclass))
{
cout<<"Unable to Register Class";
return false;
}
ULONG Window_Width;
ULONG Window_Height;
DWORD style;
bool full_screen = false;
if(full_screen)
{
Window_Width = GetSystemMetrics(SM_CXSCREEN);
Window_Height = GetSystemMetrics(SM_CYSCREEN);
style = WS_POPUP;
}
else
{
Window_Width = SCREEN_WIDTH;
Window_Height = SCREEN_HEIGHT;
style = WS_OVERLAPPED|WS_SYSMENU;
}
gHwnd = CreateWindow(TEXT("Device_Manager_Class_Name")
, TEXT("Device_Manager_Class_Title")
, style
, 0
, 0
, Window_Width
, Window_Height
, GetDesktopWindow()
, NULL
, gHinstance
, NULL);
if(!gHwnd)
{
cout<<"Unable to create the main window";
return false;
}
//ShowWindow(gHwnd, SW_SHOW);
//UpdateWindow(gHwnd);
//SetFocus(gHwnd);
return true;
}
DWORD WINAPI listenToIncomingWFSMessages2(LPVOID lpParam)
{
MSG msg;
SecureZeroMemory(&msg, sizeof(MSG));
BOOL bRet;
HWND windows_handle;
SecureZeroMemory(&windows_handle, sizeof(HWND));
windows_handle = FindWindow(TEXT("Device_Manager_Class_Name"), 0);
while( (bRet = GetMessage( &msg, windows_handle, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
What am I doing wrong here? What did I miss? If you have a better solution for what I'm about to do, please feel free to share it with me.

Direct2D Tutorial Window No-Show

I'm trying to use MSDN's Direct2D basic tutorial, but the window won't show up, it output's the normal debug info, but no window. I've tried playing about with the WinMain() parameters and the ShowWindow() function, but it still refuses to work. Allso in the debug info there's this, but i don't think it's relevant. \NVIDIA Corporation\coprocmanager\nvdxgiwrap.dll'. Cannot find or open the PDB file.
Here's the code.
#include "RenderHeader.h"
//Main window function.
int WINAPI WinMain(
HINSTANCE /* hInstance */,
HINSTANCE /* hPrevInstance */,
LPSTR /* lpCmdLine */,
int /* nCmdShow */)
{
// Use HeapSetInformation to specify that the process should
// terminate if the heap manager detects an error in any heap used
// by the process.
// The return value is ignored, because we want to continue running in the
// unlikely event that HeapSetInformation fails.
HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
if (SUCCEEDED(CoInitialize(NULL)))
{
{
GameRender app;
if (SUCCEEDED(app.Initialize()))
{
//Runs the application message loop.
app.RunMessageLoop();
}
}
CoUninitialize();
}
return 0;
}
GameRender::GameRender() :
m_hwnd(NULL),
m_pDirect2DFactory(NULL),
m_pRenderTarget(NULL),
m_pLightSlateGrayBrush(NULL),
m_pCornflowerBlueBrush(NULL)
{
}
GameRender::~GameRender()
{
SafeRelease(&m_pDirect2DFactory);
SafeRelease(&m_pRenderTarget);
SafeRelease(&m_pLightSlateGrayBrush);
SafeRelease(&m_pCornflowerBlueBrush);
}
HRESULT GameRender::Initialize()
{
HRESULT hRes;
/* Initialize device-indpendent resources, such
as the Direct2D factory.*/
hRes = CreateDeviceIndependantResources();
if (SUCCEEDED(hRes))
{
WNDCLASSEX Window = { sizeof(WNDCLASSEX) } ;
Window.style = CS_HREDRAW | CS_VREDRAW;
Window.lpfnWndProc = GameRender::WndProc;
Window.cbClsExtra = 0;
Window.cbWndExtra = sizeof(LONG_PTR);
Window.hInstance = HINST_THISCOMPONENT;
Window.hbrBackground = NULL;
Window.lpszMenuName = NULL;
Window.hCursor = LoadCursor(NULL, IDI_APPLICATION);
Window.lpszClassName = L"D2DDemoApp";
RegisterClassEx(&Window);
/* Because the CreateWindow function takes its size in pixels,
obtain the system DPI and use it to scale the window size.*/
FLOAT DpiX, DpiY;
/* The factory returns the current system DPI. This is also the value it will use
to create its own windows.*/
m_pDirect2DFactory->GetDesktopDpi(&DpiX, &DpiY);
//Create Window
m_hwnd = CreateWindow(L"D2PDemoApp",
L"Direct 2D Demo App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
static_cast<UINT>(ceil(640.f * DpiX / 96.f)),
static_cast<UINT>(ceil(480.f * DpiY / 96.f)),
NULL,
NULL,
HINST_THISCOMPONENT,
this);
hRes = m_hwnd ? S_OK : E_FAIL;
if (SUCCEEDED(hRes))
{
ShowWindow(m_hwnd, SW_SHOWNORMAL);
UpdateWindow(m_hwnd);
}
}
return hRes;
}
HRESULT GameRender::CreateDeviceIndependantResources()
{
HRESULT hr = S_OK;
//Create a direct2D Factory
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pDirect2DFactory);
return hr;
}
HRESULT GameRender::CreateDeviceDependantResources()
{
HRESULT hr = S_OK;
if(!&m_pRenderTarget)
{
RECT rc;
GetClientRect(m_hwnd, &rc);
D2D1_SIZE_U size = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top);
//Create a render target.
hr = m_pDirect2DFactory->CreateHwndRenderTarget(D2D1::RenderTargetProperties(), D2D1::HwndRenderTargetProperties(m_hwnd, size), &m_pRenderTarget);
if (SUCCEEDED(hr))
{
// Create a gray brush.
hr = m_pRenderTarget->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::LightSlateGray),
&m_pLightSlateGrayBrush);
}
if (SUCCEEDED(hr))
{
// Create a blue brush.
hr = m_pRenderTarget->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::CornflowerBlue),
&m_pCornflowerBlueBrush
);
}
}
return hr;
}
void GameRender::DiscardDeviceResources()
{
SafeRelease(&m_pRenderTarget);
SafeRelease(&m_pLightSlateGrayBrush);
SafeRelease(&m_pCornflowerBlueBrush);
}
void GameRender::RunMessageLoop()
{
MSG Message;
while (GetMessage(&Message, NULL, 0, 0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
}
HRESULT GameRender::OnDraw()
{
HRESULT hr = S_OK;
hr = CreateDeviceDependantResources();
if (SUCCEEDED(hr))
{
m_pRenderTarget->BeginDraw();
m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));
D2D1_SIZE_F rtSize = m_pRenderTarget->GetSize();
// Draw a grid background.
int width = static_cast<int>(rtSize.width);
int height = static_cast<int>(rtSize.height);
for (int x = 0; x < width; x += 10)
{
m_pRenderTarget->DrawLine(
D2D1::Point2F(static_cast<FLOAT>(x), 0.0f),
D2D1::Point2F(static_cast<FLOAT>(x), rtSize.height),
m_pLightSlateGrayBrush,
0.5f
);
}
for (int y = 0; y < height; y += 10)
{
m_pRenderTarget->DrawLine(
D2D1::Point2F(0.0f, static_cast<FLOAT>(y)),
D2D1::Point2F(rtSize.width, static_cast<FLOAT>(y)),
m_pLightSlateGrayBrush,
0.5f
);
}
// Draw two rectangles.
D2D1_RECT_F rectangle1 = D2D1::RectF(
rtSize.width/2 - 50.0f,
rtSize.height/2 - 50.0f,
rtSize.width/2 + 50.0f,
rtSize.height/2 + 50.0f
);
D2D1_RECT_F rectangle2 = D2D1::RectF(
rtSize.width/2 - 100.0f,
rtSize.height/2 - 100.0f,
rtSize.width/2 + 100.0f,
rtSize.height/2 + 100.0f
);
// Draw a filled rectangle.
m_pRenderTarget->FillRectangle(&rectangle1, m_pLightSlateGrayBrush);
// Draw the outline of a rectangle.
m_pRenderTarget->DrawRectangle(&rectangle2, m_pCornflowerBlueBrush);
hr = m_pRenderTarget->EndDraw();
}
if (hr == D2DERR_RECREATE_TARGET)
{
hr = S_OK;
DiscardDeviceResources();
}
return hr;
}
void GameRender::OnResize(UINT width, UINT height)
{
if (m_pRenderTarget)
{
// Note: This method can fail, but it's okay to ignore the
// error here, because the error will be returned again
// the next time EndDraw is called.
m_pRenderTarget->Resize(D2D1::SizeU(width,
height));
}
}
LRESULT CALLBACK GameRender::WndProc(
HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
LRESULT result = 0;
if (message == WM_CREATE)
{
LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam;
GameRender *pGameRender = (GameRender *)pcs->lpCreateParams;
::SetWindowLongPtrW(
hwnd,
GWLP_USERDATA,
PtrToUlong(pGameRender)
);
result = 1;
}
else
{
GameRender *pGameRender = reinterpret_cast<GameRender *>(static_cast<LONG_PTR>(
::GetWindowLongPtrW(
hwnd,
GWLP_USERDATA
)));
bool wasHandled = false;
if (pGameRender)
{
switch (message)
{
case WM_SIZE:
{
UINT width = LOWORD(lParam);
UINT height = HIWORD(lParam);
pGameRender->OnResize(width, height);
}
result = 0;
wasHandled = true;
break;
case WM_DISPLAYCHANGE:
{
InvalidateRect(hwnd, NULL, FALSE);
}
result = 0;
wasHandled = true;
break;
case WM_PAINT:
{
pGameRender->OnDraw();
ValidateRect(hwnd, NULL);
}
result = 0;
wasHandled = true;
break;
case WM_DESTROY:
{
PostQuitMessage(0);
}
result = 1;
wasHandled = true;
break;
}
}
if (!wasHandled)
{
result = DefWindowProc(hwnd, message, wParam, lParam);
}
}
return result;
}
Assuming that "RenderHeader.h" exists in your project's directory and it includes the windows header, then your problem is that you're not passing WinMain the variables it needs to function. 'HINSTANCE', 'LPSTR' and 'int' are all variable types, but you need to give them a name, otherwise they don't exist and the function won't work.
So this would be right
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int uCmdShow )
{
// The rest of the code
}
The names of the variables are commented out on the code in your question :P