Sign in to follow this  

[DirectX & WinAPI] crash with GetOpenFileName dialog box

This topic is 2058 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

Hey,
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.
[CODE]int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR CommandLine, int nCmdShow)
{
// Creating window here and initialising DirectX

//this loads common modern controls
INITCOMMONCONTROLSEX cc;
cc.dwSize=sizeof(INITCOMMONCONTROLSEX);
cc.dwICC= ICC_STANDARD_CLASSES;
InitCommonControlsEx(&cc);

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?
{
TranslateMessage(&msg);
DispatchMessage(&msg);
//Render() function is ran as an answer to WM_PAINT message in WindowProcedure callback function.
}
return msg.wParam;
}[/CODE]
[CODE]void Input::CreateInterface(HINSTANCE hInstance)
{
//Creating common Loading file dialog box
OPENFILENAME ofn;

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.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.hwndOwner = hwnd;

GetOpenFileName( & ofn );
}[/CODE]
[CODE]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);

Input::Obj().Sprite->End();

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;
}[/CODE]

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][color=#666600].[/color][color=#000000]lpstrFile [/color][color=#666600]=[/color][color=#000000] [/color][color=#660066]Input[/color][color=#666600]::[/color][color=#660066]Obj[/color][color=#666600]().[/color][color=#660066]FileName[/color][color=#666600];[/color]
Are you sure the buffer is being well formed and not too small?

[i]Pozdrawiam[/i] [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by kubera

Share this post


Link to post
Share on other sites

This topic is 2058 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