• Advertisement
Sign in to follow this  

[DirectX & WinAPI] crash with GetOpenFileName dialog box

This topic is 2149 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 came across very strange problem in my application and can't firgure out the solution... The error occurs only if I'am creating the GetOpenFileName dialog box. I have described the problem as comments in code below.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR CommandLine, int nCmdShow)
// Creating window here and initialising DirectX

//this loads common modern controls

Input::Obj().CreateInterface(hInstance); /* the code of this function is below. When I put it before LoadTextures() debugger gives an error in Render() function, but when I put this function after LoadTextures() everything works fine...*/
Graphics::Obj().LoadTextures(); //in this function I load sprites and do: D3DXCreateSprite(Input::Obj().d3dDevice, &Input::Obj().Sprite);

ShowWindow( Input::Obj().hwnd, nCmdShow );
UpdateWindow( Input::Obj().hwnd );

MSG msg;
ZeroMemory(&msg, sizeof(msg));

while(GetMessage(&msg, NULL, 0, 0) > 0) //NAJPOPRAWNIEJSZA FORMA, while czy if?
//Render() function is ran as an answer to WM_PAINT message in WindowProcedure callback function.
return msg.wParam;

void Input::CreateInterface(HINSTANCE hInstance)
//Creating common Loading file dialog box

ZeroMemory( & ofn, sizeof( ofn ) );
ofn.lStructSize = sizeof( ofn );
ofn.lpstrFilter = "text files (*.txt)\0*.txt\0";
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFile = Input::Obj().FileName;
ofn.lpstrDefExt = "txt";
ofn.hwndOwner = hwnd;

GetOpenFileName( & ofn );

bool Graphics::Render()
HRESULT hr = Input::Obj().d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);
if(FAILED(hr)) return false;

hr = Input::Obj().d3dDevice->BeginScene();
if(FAILED(hr)) return false;

Input::Obj().Sprite->Begin(D3DXSPRITE_ALPHABLEND); /*when CreateInterface(...) function is before LoadTextures debugger gives error here, saying Unhandled exception at 0x00412cac in program.exe: 0xC0000005: Access violation reading location 0x00000000.*/

Input::Obj().DrawSprite(500, 680, 1, 0, 0, Input::Obj().Tex_width[0], Input::Obj().Tex_height[0], false, 0);


hr = Input::Obj().d3dDevice->EndScene();
if(FAILED(hr)) return false;

hr = Input::Obj().d3dDevice->Present(NULL, NULL, NULL, NULL);
if(FAILED(hr)) return false;

return true;

It just drives me mad how replacing 2 functions (LoadTextures() and CreateInterface(...)) makes this program crashing... Even if LoadTextures is empty inside if it is ran before CreateInterface debugger doesn't shout. When I run my program without LoadTextures() function it crashes just like when I call this function after CreateInterface(...).
I would be really very grateful for help Edited by savail

Share this post

Link to post
Share on other sites
What is the size of this in TCHARs:

[color=#000000]ofn[color=#666600].[color=#000000]lpstrFile [color=#666600]=[color=#000000] [color=#660066]Input[color=#666600]::[color=#660066]Obj[color=#666600]().[color=#660066]FileName[color=#666600];
Are you sure the buffer is being well formed and not too small?

Pozdrawiam smile.png Edited by kubera

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement