1LINK : fatal error LNK1168: cannot open C:\Users\.............
I keep getting this error, so i have to go to task manager, kill the project, and then compile it again. This didn't use to happen before, so why is it happening now?
I don't know if it's relevent, but I'm writing directX code.
You mean the application doesn't terminate properly and the linker can't overwrite the file when it's still in use?
Well, then the obvious solution is to fix the code so that the application exits normally. :)
Perhaps it's a memory leak, threads not terminating etc. Hard to tell from here of course.
Perhaps it's a memory leak, threads not terminating etc. Hard to tell from here of course.
Quote:Original post by Waaayoff
win32
Just guessing: forgot a PostQuitMessage call?
If it's not too much code (one or two relatively small files), or you are able to strip out most of the source while still being able to reproduce this problem, you can try to post it here and perhaps someone can give you some insight.
It's an extremely simple project, just draws a rotating cube with directional light.. (still a beginner :))
All the directx code is below the WndProc function so it'll be easy to go thru the win32 code..
All the directx code is below the WndProc function so it'll be easy to go thru the win32 code..
// Moving Objects.cpp : Defines the entry point for the application.//#include "stdafx.h"#include <d3d9.h>#include <d3dx9.h>#include "Moving Objects.h"#pragma comment (lib,"d3d9.lib")#pragma comment (lib,"d3dx9.lib")#define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_NORMAL)struct CUSTOMVERTEX { float x,y,z; D3DVECTOR Normal;};int ScreenWidth = 1280;int ScreenHeight = 800;// D3D Variables & DeclarationsLPDIRECT3DVERTEXBUFFER9 v_buffer;LPDIRECT3DINDEXBUFFER9 i_buffer;LPDIRECT3D9 d3d;LPDIRECT3DDEVICE9 d3ddev;void CleanD3D();void RenderFrame();void Initialize(HWND);void Graphics();ATOM MyRegisterClass(HINSTANCE hInstance);LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){ MSG msg; HWND hWnd; MyRegisterClass(hInstance); hWnd = CreateWindowEx(NULL, L"Class", L"Moving Objects", WS_OVERLAPPEDWINDOW, 100, 100, 900,600, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); Initialize(hWnd); while (TRUE) { while (PeekMessage(&msg,hWnd,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } if (msg.wParam == WM_QUIT) break; RenderFrame(); } CleanD3D(); return (int) msg.wParam;}ATOM MyRegisterClass(HINSTANCE hInstance){ WNDCLASSEX wcex; ZeroMemory(&wcex,sizeof(wcex)); wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.hInstance = hInstance; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszClassName = L"Class"; return RegisterClassEx(&wcex);}LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ switch (message) { case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;}void Initialize(HWND hWnd) { d3d = Direct3DCreate9(D3D_SDK_VERSION); D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp,sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hWnd; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&d3ddev); d3ddev->SetRenderState(D3DRS_LIGHTING,TRUE); d3ddev->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE); d3ddev->SetRenderState(D3DRS_ZENABLE,TRUE); d3ddev->SetRenderState(D3DRS_AMBIENT,D3DCOLOR_XRGB(50,50,50)); D3DLIGHT9 Light; ZeroMemory(&Light,sizeof(Light)); Light.Type = D3DLIGHT_DIRECTIONAL; Light.Diffuse = D3DXCOLOR(0.4,0.4,0.4,1.0); Light.Direction = D3DXVECTOR3(-4.0,1.0,-1.0); d3ddev->SetLight(0,&Light); d3ddev->LightEnable(0,TRUE); D3DMATERIAL9 Material; ZeroMemory(&Material,sizeof(Material)); Material.Ambient = D3DXCOLOR(1.0,1.0,1.0,1.0); Material.Diffuse = D3DXCOLOR(0.7,0.7,0.7,0.7); d3ddev->SetMaterial(&Material); Graphics();}void RenderFrame() { static float index(0); index += 2.0; d3ddev->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0); d3ddev->Clear(0,NULL,D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),1.0f,0); d3ddev->BeginScene(); d3ddev->SetFVF(CUSTOMFVF); D3DXMATRIX RotateY, Scale; D3DXMatrixRotationY(&RotateY,D3DXToRadian(index)); D3DXMatrixScaling(&Scale,0.7,0.7,0.7); d3ddev->SetTransform(D3DTS_WORLD,&(RotateY * Scale)); D3DXMATRIX View; D3DXMatrixLookAtLH(&View, &D3DXVECTOR3(0.0,5.0,15.0), &D3DXVECTOR3(0.0,0.0,0.0), &D3DXVECTOR3(0.0,1.0,0.0)); d3ddev->SetTransform(D3DTS_VIEW,&View); D3DXMATRIX Projection; D3DXMatrixPerspectiveFovLH(&Projection, D3DXToRadian(45), (FLOAT)ScreenWidth/(FLOAT)ScreenHeight, 1.0, 100.0); d3ddev->SetTransform(D3DTS_PROJECTION,&Projection); d3ddev->SetStreamSource(0,v_buffer,0,sizeof(CUSTOMVERTEX)); d3ddev->SetIndices(i_buffer); d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,28,0,14); d3ddev->EndScene(); d3ddev->Present(NULL,NULL,NULL,NULL);}void CleanD3D() { v_buffer->Release(); d3ddev->Release(); d3d->Release();}void Graphics() { CUSTOMVERTEX Vertex[] = { {-3.0,3.0,3.0, 0.0,0.0,1.0 }, // front side {-3.0,-3.0,3.0, 0.0,0.0,1.0 }, {3.0,-3.0,3.0, 0.0,0.0,1.0 }, {3.0,3.0,3.0, 0.0,0.0,1.0 }, {3.0,3.0,3.0, 1.0,0.0,0.0 }, // right side {3.0,-3.0,3.0, 1.0,0.0,0.0 }, {3.0,-3.0,-3.0, 1.0,0.0,0.0 }, {3.0,3.0,-3.0, 1.0,0.0,0.0 }, {-3.0,3.0,-3.0, 0.0,0.0,-1.0}, // back side {-3.0,-3.0,-3.0, 0.0,0.0,-1.0}, {3.0,-3.0,-3.0, 0.0,0.0,-1.0}, {3.0,3.0,-3.0, 0.0,0.0,-1.0}, {-3.0,3.0,3.0, -1.0,0.0,0.0 }, // left side {-3.0,-3.0,3.0, -1.0,0.0,0.0 }, {-3.0,-3.0,-3.0, -1.0,0.0,0.0 }, {-3.0,3.0,-3.0, -1.0,0.0,0.0 }, {-3.0,3.0,-3.0, 0.0,1.0,0.0 }, // upper side {-3.0,3.0,3.0, 0.0,1.0,0.0 }, {3.0,3.0,3.0, 0.0,1.0,0.0 }, {3.0,3.0,-3.0, 0.0,1.0,0.0 }, {-3.0,-3.0,-3.0, 0.0,-1.0,1.0 }, // lower side {-3.0,-3.0,3.0, 0.0,-1.0,1.0 }, {3.0,-3.0,3.0, 0.0,-1.0,1.0 }, {3.0,-3.0,-3.0, 0.0,-1.0,1.0 }, {-5.0,5.0,5.0, 4.0,-1.0,1.0 }, // Rotated Square {-5.0,-5.0,5.0, 4.0,-1.0,1.0 }, {-7.0,-5.0,3.0, 4.0,-1.0,1.0 }, {-7.0,5.0,3.0, 4.0,-1.0,1.0 }, }; short Indices[] = { 0,1,2, // front side 2,3,0, 4,5,6, // right side 6,7,4, 8,9,10, // back side 10,11,8, 12,13,14, // left side 14,15,12, 16,17,18, // upper side 18,19,16, 20,21,22, // lower side 22,23,20, 24,25,26, // square 26,27,24 }; d3ddev->CreateVertexBuffer(28*sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL); void* pVoid; v_buffer->Lock(0,0,(void**)&pVoid,0); memcpy(pVoid,Vertex,sizeof(Vertex)); v_buffer->Unlock(); d3ddev->CreateIndexBuffer(42*sizeof(short), 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &i_buffer, NULL); i_buffer->Lock(0,0,(void**)&pVoid,0); memcpy(pVoid,Indices,sizeof(Indices)); i_buffer->Unlock();}
Quote:Original post by Waaayoff
It's an extremely simple project, just draws a rotating cube with directional light.. (still a beginner :))
All the directx code is below the WndProc function so it'll be easy to go thru the win32 code..
*** Source Snippet Removed ***
You're testing for a quit message outside the message loop:
while (PeekMessage(&msg,hWnd,0,0,PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg);}if (msg.wParam == WM_QUIT) break;
Something else: it isn't strictly wrong but perhaps a little confusing:
switch (message){case WM_DESTROY: PostQuitMessage(0); break;default: return DefWindowProc(hWnd, message, wParam, lParam);}return 0;
At first it looks like the function returns 0 by default. However the default case label ensures that it will always return the result of DefWindowProc. This would be clearer:
switch (message){case WM_DESTROY: PostQuitMessage(0); break;}return DefWindowProc(hWnd, message, wParam, lParam);
Oohh!! I filled the 2nd parameter of PeekMessagw with NULL instead of hWnd and it worked, no idea why.. I only have one window so it shouldn't make a difference.. bah..
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement