c++ - Cannot start DirectX 11 executable with Visual Studio, Build works properly -
following directx 11 code, displays window , keeps open waiting messages:
#include "stdafx.h" #include <iostream> lresult callback windowproc(_in_ hwnd hwnd, _in_ uint umsg, _in_ wparam wparam, _in_ lparam lparam) { if (umsg == wm_destroy) { postquitmessage(0); return 0; } return defwindowproc(hwnd, umsg, wparam, lparam); } // directx main int winapi wwinmain(hinstance hinstance, hinstance previnstance, lpwstr cmd, int ncmdshow) { wndclassex window; zeromemory(&window, sizeof(wndclassex)); window.cbsize = sizeof(wndclassex); window.hbrbackground = (hbrush) color_window; window.hinstance = hinstance; window.lpfnwndproc = windowproc; window.lpszclassname = (lpcwstr)"mainwindow"; // class name window.style = cs_hredraw | cs_vredraw; registerclassex(&window); hwnd windowhandle = createwindow((lpcwstr)"main window", (lpcwstr)"directx tut!", ws_overlappedwindow, 100, 100, 600, 800, null, null, hinstance, 0); if (!windowhandle) return -1; showwindow(windowhandle, ncmdshow); msg message; while (getmessage(&message, null, 0, 0)) // continuously loop messages { dispatchmessage(&message); } return 0; }
stdafx.h
precompiled header file in include directx includes. namely in c:\program files (x86)\windows kits\8.1\include\shared;c:\program files (x86)\windows kits\8.1\include\um;
i include c:\program files (x86)\windows kits\8.1\include\shared;c:\program files (x86)\windows kits\8.1\include\um;
libraries located in c:\program files (x86)\windows kits\8.1\lib\winv6.3\um\x64
i'm using visual studio 2015, windows 8.1 64bit. followed this tutorial create directx application. made win32 project, done these modifications in include , libs, pasted code , built properly. running not output anything. says build succeeded. vs works other projects. have tried configurations in x64 mode. if had guess i'd not finding dll.. cannot find culprit.
you have specified "mainwindow" it's class name when registering window class when creating window have specified ""main window", windows unable find class. passing "mainwindow" it's class name createwindow fix issue:
window.lpszclassname = l"mainwindow"; // class name window.style = cs_hredraw | cs_vredraw; registerclassex(&window); hwnd windowhandle = createwindow(l"mainwindow", l"directx tut!", ws_overlappedwindow, 100, 100, 600, 800, null, null, hinstance, 0);
as shown above, should use l prefix wide character string literals
Comments
Post a Comment