I’m trying to get this simple windows dialog to spawn but as soon as I start it it reports “Error x715” which means hDialog was not correctly made in the int WINAPI WinMain() function. It compiles just fine.
I’m working in Visual Studio 2010 and it’s a “Visual C++ -> Empty Project” project.
This is the full main.cpp file, which is the only file in the project:
#include "windows.h"
#define DLG_MAIN 200 // ID for dialog
#define DLG_ICON 30000 // IDs for icons
#define DLG_ICON_S 30000
#define IDC_QUIT 1011 // ID for "quit"-button
#define IDC_INFO 2000 // ID for "info"-button
#define ID_TIMER 1 // ID for timer
#define IDC_STATIC -1 // ID for all labels
#define TIMER_INTERRUPT 500 // timer msg interval in msec
HINSTANCE TheInstance = 0; // instance handle of this program
// Our main function
void lalala(HWND hwnd)
{
/*Doesn't do anything yet.*/
}
// Windows passes messages to application windows to indicate "something"
// needs to be done
BOOL CALLBACK DialogProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
// set the time to generate a timer message (WM_TIMER)
SetTimer(hwnd, ID_TIMER, TIMER_INTERRUPT, NULL);
return TRUE;
case WM_TIMER:
// a timer msg was received so call our main function!
lalala(hwnd);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_INFO:
// the info button on the window was pressed
MessageBox(hwnd, "<show some info>", "The Jonas Brothers are way better than Nick Cave ever was.", MB_OK);
return TRUE;
case IDC_QUIT:
// the quit button on the window was pressed
PostQuitMessage(0);
return TRUE;
}
return TRUE;
case WM_DESTROY:
// this app is about to be closed so kill the timer
KillTimer(hwnd, ID_TIMER);
PostQuitMessage(0);
return TRUE;
case WM_CLOSE:
// destroy the window
DestroyWindow (hwnd);
return TRUE;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow)
{
TheInstance = hInst;
HWND hDialog = 0;
hDialog = CreateDialog (hInst, MAKEINTRESOURCE (DLG_MAIN), 0, (DLGPROC)DialogProc);
if (!hDialog)
{
char buf [100];
wsprintf (buf, "Error x%x", GetLastError ());
MessageBox (0, buf, "CreateDialog", MB_ICONEXCLAMATION | MB_OK);
return 1;
}
HICON hIcon = LoadIcon (TheInstance, MAKEINTRESOURCE (DLG_ICON));
SendMessage (hDialog, WM_SETICON, WPARAM (TRUE), LPARAM (hIcon));
hIcon = LoadIcon (TheInstance, MAKEINTRESOURCE (DLG_ICON_S));
SendMessage (hDialog, WM_SETICON, WPARAM (FALSE), LPARAM (hIcon));
MSG msg;
int status;
while ((status = GetMessage (&msg, 0, 0, 0)) != 0)
{
if (status == -1) return -1;
if (!IsDialogMessage (hDialog, &msg))
{
TranslateMessage ( &msg );
DispatchMessage ( &msg );
}
}
return msg.wParam;
}
Can anyone tell me why it fails at hDialog = CreateDialog (hInst, MAKEINTRESOURCE (DLG_MAIN), 0, (DLGPROC)DialogProc); ?
Error 0x715 is ERROR_RESOURCE_NAME_NOT_FOUND, which you get when it fails to find the dialog with the name that you supplied, in the resource section. Instead of declaring the macros for each resources, just use
#include "resource.h"