linking error

Hello all,

I am facing the below error in my program. Program compiles for the first time correctly and shows output. However, while I run for 2nd time, the below error appears. I could see .exe file still running in task manager. Once I manually end the process from task manager, program compiles correctly. But for second time again the error come.

1
2
3
4
5
Linking...
LINK : fatal error LNK1168: cannot open Debug/windows3.exe for writing
Error executing link.exe.

windows3.exe - 1 error(s), 0 warning(s)
Post your code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef UNICODE
#define UNICODE
#endif 

#include "stdafx.h"
#include "windows.h"

WNDCLASS a;

long _stdcall myfunc(HWND,UINT,UINT,LONG);

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	HWND h;

	MSG m;
	
	a.hInstance=hInstance;
	a.lpszClassName="my";
//a.hIcon=(struct HICON__ *)1;
	a.lpfnWndProc=myfunc;
	a.hbrBackground=(struct HBRUSH__ *)GetStockObject(COLOR_BACKGROUND|COLOR_INACTIVEBORDER);

	RegisterClass(&a);

	h=CreateWindow("my","title",WS_OVERLAPPEDWINDOW,20,20,300,200,0,0,hInstance,0);
	ShowWindow(h,1);

	while(GetMessage(&m,0,0,0))
		DispatchMessage(&m);


	return 0;
}


long _stdcall myfunc(HWND w,UINT x,UINT y,LONG z)
{
	switch(x)
	{
/*	case WM_DESTROY:
		PostQuitMessage(0);
		break;*/
	case WM_CLOSE:
		if(MessageBox(w,"Really want to quit?","Quit",MB_OKCANCEL)==IDOK)
		{
			DestroyWindow(w);
		}
		else return 0;

	default:
		return DefWindowProc(w,x,y,z);
	}

	return 0;
}

You aren't initializing all fields of your window class. That's very, very bad.

The problem is, your program does not finish when the window is destroyed. In your window function, insert the following inside the switch:

1
2
3
case WM_DESTROY:
PostQuitMessage(0);
return 0;


Oh, and replace _stdcall by CALLBACK. CALLBACK is a macro that usually resolves to _stdcall, but it's more readible, and in theory it could resolve to other things aswell.
ok thanks. I just started with windows programming and this was my first program.
Thanks for the response.
Topic archived. No new replies allowed.