Window Problems

Started by
7 comments, last by Programmer101 16 years, 2 months ago
I've recently started to have some strange problems with windows programming. I also recently installed the new windows sdk so I can't help wondering whether or not this is my problem. Anyway, the issue is that when I try to create an empty window it will open and there are no problems; however, the next time I try to recompile, it gives me this message:
1>Linking...
1>LINK : fatal error LNK1104: cannot open file 'C:\Programing\KaBoom\Release\KaBoom.exe'
I am also unable to delete the file because it is "in use" which I'm guessing is because it is still running. I then open task manager and look through the current processes, but the program is not there. I don't understand this! I have to log out of my account and log back on before I can recompile which is extremely annoying. I've never had this problem before, so I'm just wondering why this is now happening. Has something in windows programming changed? Am I missing something? The problem that I described above happens for any blank window. I actually have another problem. I wrote a very simple windows program, but this window won't even open. I don't know what is wrong. I'll post the code. It produces both the first and second problems:
int PASCAL wWinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPWSTR lpCmdLine, int nCmdShow)
{
	MSG msg = {0};
	WNDCLASS wc;

	//Copy hinst
	g_hInst = hInst;

	//Initialize COM
	if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
	{
		MessageBox(NULL, "Failed to initialize COM.", "Error", MB_OK);
		return FALSE;
	}

	//Create and register the window class
	ZeroMemory(&wc, sizeof(wc));
	wc.hInstance     = hInst;
	wc.lpfnWndProc   = WindowProc;
	wc.lpszClassName = "KaBoom";
	wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);
	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wc.hIcon         = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));
	if(!RegisterClass(&wc)) {
		MessageBox(NULL, "Failed to register window class.", "Error", MB_OK);
		CoUninitialize();
		return FALSE;
	}

	//Create the main window
	g_hWnd = CreateWindow("KaBoom!", "KaBoom!",
						  WS_OVERLAPPEDWINDOW,
						  0, 0,
						  300, 300,
						  0, 0, g_hInst, 0);

	//Succeeded, continue into app
	if(g_hWnd)
	{

		// Main message loop
        while(GetMessage(&msg,NULL,0,0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
	} else {
		MessageBox(NULL, "Failed to create main window", "Error", MB_OK);
	}

	CoUninitialize();

	return TRUE;
}
When I run it I get "Failed to create main window" and then I am unable to rebuild. Thank you very much.
Advertisement
the window failed to be created because in your WNDCLASS you specify "KaBoom" as your classname and in the CreateWindow function you specify "KaBoom!" as your classname.

on a funnier, historical note, int PASCAL WinMain... now that's old school ha ha ha. i haven't seen that notation for about 12 or 13 years. we used to use PASCAL when writing 16-bit code for windows 3.1. even though PASCAL, APIENTRY, and WINAPI all mean _stdcall, PASCAL and APIENTRY are archaic terms.

[Edited by - yadango on February 7, 2008 10:26:28 PM]
Oh my, using COM now are you? I sure hope you know what you're in for. [smile]
Ok, thanks for the help. I still don't understand why I can't rebuild the program. As I said it tells me that it is "in use" when I try to delete it and I'm unable to rebuild because of this. Any suggestions?

All I've ever used is int PASCAL, so what do people use now. What do you use?

As for COM, I'm pretty sure that you have to use it in order to use DirectShow, right?
You're probably not exiting your program when the window is closed. Have you made sure you've killed the debugger, or are you just closing the window?
Are you calling PostQuitMessage once you close the window?

If not your window may be destroyed but the main message pump is still running (GetMessage only returns 0 if it receives WM_QUIT).

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Quote:Original post by f8k8
You're probably not exiting your program when the window is closed. Have you made sure you've killed the debugger, or are you just closing the window?


Nope, the debugger is not still running. Also, as I said, the program does not show up in the task manager process list when I check.

Quote:Original post by Endurion
Are you calling PostQuitMessage once you close the window?

If not your window may be destroyed but the main message pump is still running (GetMessage only returns 0 if it receives WM_QUIT).


Yes, I do call PostQuitMessage. If you want to see the full code I'll post it, its not that long:

long FAR PASCAL WindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){	//Handle message	switch(message)	{	case WM_KEYDOWN:        switch( wParam )        {            case VK_ESCAPE:            case VK_RETURN:				PostQuitMessage(0);                break;			case VK_SPACE:				break;			case VK_LEFT:				break;        }        break;	case WM_DESTROY:		PostQuitMessage(0);		return 0;	}	return (LONG) DefWindowProc(hWnd, message, wParam, lParam);}int PASCAL wWinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPWSTR lpCmdLine, int nCmdShow){	MSG msg = {0};	WNDCLASS wc;	//Copy hinst	g_hInst = hInst;	//Initialize COM	if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))	{		MessageBox(NULL, "Failed to initialize COM.", "Error", MB_OK);		return FALSE;	}	//Create and register the window class	ZeroMemory(&wc, sizeof(wc));	wc.hInstance     = hInst;	wc.lpfnWndProc   = WindowProc;	wc.lpszClassName = "KaBoom";	wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);	wc.hIcon         = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));	if(!RegisterClass(&wc)) {		MessageBox(NULL, "Failed to register window class.", "Error", MB_OK);		CoUninitialize();		return FALSE;	}	//Create the main window	g_hWnd = CreateWindow("KaBoom", "KaBoom!",						  WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,						  0, 0,						  300, 300,						  0, 0, g_hInst, 0);	//Display the window	ShowWindow(g_hWnd, SW_NORMAL);	//Update window	UpdateWindow(g_hWnd);	//Succeeded, continue into app	if(g_hWnd)	{		//Save menu handle		g_hMenu = GetMenu(g_hWnd);		// Main message loop        while(GetMessage(&msg,NULL,0,0))		{            TranslateMessage(&msg);            DispatchMessage(&msg);			if(msg.message == WM_QUIT || msg.message == WM_CLOSE)				break;        }	} else {		MessageBox(NULL, "Failed to create main window", "Error", MB_OK);	}	PostQuitMessage(0);	UnregisterClass("KaBoom", hInst);	CoUninitialize();	return TRUE;}


This doesn't make any sense. Thanks for all of the suggestions guys.
It's weird.

The snippet you showed has some flaws but it does exit fine. Is that the exact code or are there some parts missing?


About the flaws:

-The PostQuitMessage call after the message loop is not necessary. You won't need it any more.
-Try to put the PostQuitMessage call only at one position. Let the key-handlers simply close the main window and leave the PostQuitMessage call inside WM_DESTROY.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

I don't understand [bawling]

All of a sudden it's working, but I know that any minute it will start giving me that error again. I've got my fingers crossed. Heres the full source in case anyone is wondering:

main.cpp
//Direct show includes#include <dshow.h>#include <d3d9.h>#include <vmr9.h>//Windows includes#include <windows.h>#include <commctrl.h>#include <commdlg.h>#include <stdio.h>//Project include#include "KaBoom.h"#include "resource.h"//DirectShow interfacesIGraphBuilder *pGB = NULL;IMediaControl *pMC = NULL;IMediaEventEx *pME = NULL;IBasicAudio   *pBA = NULL;IMediaSeeking *pMS = NULL;IMediaPosition *pMP = NULL;IVideoFrameStep *pFS = NULL;//VMR9 render interfaceIVMRWindowlessControl9 *pWC = NULL;//Global dataHINSTANCE g_hInst = 0;HWND g_hWnd = 0;HMENU g_hMenu = 0;RECT g_vidDest = {0};PLAYSTATE g_State;long FAR PASCAL WindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){	//Handle message	switch(message)	{	case WM_KEYDOWN:        switch( wParam )        {            case VK_ESCAPE:            case VK_RETURN:				PostQuitMessage(0);                break;			case VK_SPACE:				break;			case VK_LEFT:				break;        }        break;	case WM_DESTROY:		PostQuitMessage(0);		return 0;	}	return (LONG) DefWindowProc(hWnd, message, wParam, lParam);}int PASCAL wWinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPWSTR lpCmdLine, int nCmdShow){	MSG msg = {0};	WNDCLASS wc;	//Copy hinst	g_hInst = hInst;	//Initialize COM	if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))	{		MessageBox(NULL, "Failed to initialize COM.", "Error", MB_OK);		return FALSE;	}	//Set state to loading	g_State = LOADING;	//Create and register the window class	ZeroMemory(&wc, sizeof(wc));	wc.hInstance     = hInst;	wc.lpfnWndProc   = WindowProc;	wc.lpszClassName = "KaBoom";	wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);	wc.hIcon         = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));	if(!RegisterClass(&wc)) {		MessageBox(NULL, "Failed to register window class.", "Error", MB_OK);		CoUninitialize();		return FALSE;	}	//Create the main window	g_hWnd = CreateWindow("KaBoom", "KaBoom!",						  WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,						  0, 0,						  300, 300,						  0, 0, g_hInst, 0);	//Display the window	ShowWindow(g_hWnd, SW_NORMAL);	//Update window	UpdateWindow(g_hWnd);	//Succeeded, continue into app	if(g_hWnd)	{		//Save menu handle		g_hMenu = GetMenu(g_hWnd);		// Main message loop        while(GetMessage(&msg,NULL,0,0))		{            TranslateMessage(&msg);            DispatchMessage(&msg);			if(msg.message == WM_QUIT || msg.message == WM_CLOSE)				break;        }	} else {		MessageBox(NULL, "Failed to create main window", "Error", MB_OK);	}	UnregisterClass("KaBoom", hInst);	CoUninitialize();	return TRUE;}


KaBoom.h
//Application media stateenum PLAYSTATE {RUNNING, PAUSED, STOPPED, LOADING};//File filter#define FILE_FILTER_TEXT     TEXT("Video Files (*.asf; *.avi; *.qt; *.mov; *.mpg; *.mpeg; *.m1v; *.wmv)\0*.asf; *.avi; *.qt; *.mov; *.mpg; *.mpeg; *.m1v; *.wmv\0")    TEXT("Audio files (*.wav; *.mpa; *.mp2; *.mp3; *.au; *.aif; *.aiff; *.snd)\0*.wav; *.mpa; *.mp2; *.mp3; *.au; *.aif; *.aiff; *.snd\0")    TEXT("MIDI Files (*.mid, *.midi, *.rmi)\0*.mid; *.midi; *.rmi\0")     TEXT("Image Files (*.jpg, *.bmp, *.gif, *.tga)\0*.jpg; *.bmp; *.gif; *.tga\0")     TEXT("All Files (*.*)\0*.*;\0\0")//Defaults#define DEFAULT_WIDTH  320#define DEFAULT_HEIGHT 240


Thanks for all of your help! Hopefully I won't be reposting on this forum any time soon!

This topic is closed to new replies.

Advertisement