Sign in to follow this  

Window Problems

This topic is 3600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 interfaces
IGraphBuilder *pGB = NULL;
IMediaControl *pMC = NULL;
IMediaEventEx *pME = NULL;
IBasicAudio *pBA = NULL;
IMediaSeeking *pMS = NULL;
IMediaPosition *pMP = NULL;
IVideoFrameStep *pFS = NULL;

//VMR9 render interface
IVMRWindowlessControl9 *pWC = NULL;

//Global data
HINSTANCE 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 state
enum 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!

Share this post


Link to post
Share on other sites

This topic is 3600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this