petpan24

At the moment i'm programming a 2d graphical engine with directX9, but when i try to run the function D3DXGetImageInfoFromFile((LPCWSTR) filename, &imginfo); it gives back an undefined error code, i'm using the directx october 2005 sdk with the latest version of the directx runtimes.

Full engine

GraphEngine.h:
#pragma
once

class GraphEngine;

#include <D3d9.h>

#include <Windows.h>

#include "GraphResource.h"

class GraphEngine

{

public:

IDirect3D9 *D3D;

IDirect3DDevice9 *D3DDevice;

IDirect3DSurface9 *D3DScreen;

GraphEngine(HWND hWnd);

~GraphEngine(void);

void drawImage(GraphResource *img, int X, int Y);

void RefreshScreen();

};

GraphEngine.cpp:

#include "StdAfx.h"

#include "GraphEngine.h"

GraphEngine::GraphEngine(HWND hWnd)

{

// Locals

D3DPRESENT_PARAMETERS devParam;

// Get Direct3D9 interface

D3D = Direct3DCreate9(D3D_SDK_VERSION);

if (D3D == NULL) throw new char[] = "Direct3D Initialization problems";

// Get a Device

// Give Screensize

devParam.BackBufferWidth = 1024;

devParam.BackBufferHeight = 768;

devParam.BackBufferFormat = D3DFMT_X8R8G8B8;

devParam.BackBufferCount = 1;

devParam.MultiSampleType = D3DMULTISAMPLE_NONE;

devParam.MultiSampleQuality = 0;

devParam.SwapEffect = D3DSWAPEFFECT_FLIP;

devParam.hDeviceWindow = hWnd;

devParam.Windowed = false;

devParam.EnableAutoDepthStencil = false;

devParam.Flags = 0;

devParam.FullScreen_RefreshRateInHz = 60;

devParam.PresentationInterval = D3DPRESENT_INTERVAL_ONE;

if (FAILED(D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_MIXED_VERTEXPROCESSING, &devParam, &D3DDevice)))

throw new char[] = "Cannot create device";

// Get the backbuffer surface

if (FAILED(D3DDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &D3DScreen)))

throw new char[] = "Cannot get back buffer";

}

GraphEngine::~GraphEngine(void)

{

// Release last Backbuffer

if (D3DScreen != NULL)

{

D3DScreen->Release();

D3DScreen = NULL;

}

// Release Device

if (D3DDevice != NULL)

{

D3DDevice->Release();

D3DDevice = NULL;

}

// Release Direct3D9 object

if (D3D != NULL)

{

D3D->Release();

D3D = NULL;

}

}

void GraphEngine::drawImage(GraphResource *img, int X, int Y)

{

// Locals

D3DSURFACE_DESC imgSize;

RECT imgRect;

POINT dest;

// Get Surface descriptor

img->Image->GetDesc(&imgSize);

// Fill rectangle

imgRect.left = 0;

imgRect.top = 0;

imgRect.right = imgSize.Width;

imgRect.bottom = imgSize.Height;

// Do the actual copying

if (FAILED(D3DDevice->UpdateSurface(img->Image, &imgRect, D3DScreen, &dest)))

throw new char[] = "Cannot draw image";

}

void GraphEngine::RefreshScreen()

{

// Refresh the screen

D3DDevice->Present(NULL, NULL, NULL, NULL);

// Get the backbuffer surface

if (FAILED(D3DDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &D3DScreen)))

throw new char[] = "Cannot get back buffer";

}

GraphResource.h:

#pragma once

#include <D3d9.h>

class GraphResource;

#include "GraphEngine.h"

class GraphResource

{

public:

GraphResource(void);

~GraphResource(void);

void Load(char *filename, GraphEngine *eng);

IDirect3DSurface9 *Image;

};

GraphResource.cpp:

#include "StdAfx.h"

#include "GraphResource.h"

#include <D3dx9.h>

#include <stdio.h>

GraphResource::GraphResource(void)

{

}

GraphResource::~GraphResource(void)

{

// Release imagefile

if (Image != NULL)

{

Image->Release();

}

}

void GraphResource::Load(char *filename, GraphEngine *eng)

{

// Locals

D3DXIMAGE_INFO imginfo;

D3DCOLOR transparent;

RECT tlrect;

D3DLOCKED_RECT lrect;

FILE *debug;

HRESULT tresult;

// Get image information

//tresult = D3DXGetImageInfoFromFile((LPCWSTR) filename, &imginfo);

tresult = D3DXGetImageInfoFromFile("test.bmp", &imginfo); // HERE GOES IT WRONG

if (FAILED(tresult))

//if (FAILED(D3DXGetImageInfoFromFile((LPCWSTR) filename, &imginfo)))

throw new char[] = "Cannot get image information";

debug = fopen("debug.txt", "w");

fprintf(debug, "%d\n", &(imginfo.Width));

fprintf(debug, "%d\n", &(imginfo.Height));

fclose(debug);

// Allocate surface for the image

if (FAILED(eng->D3DDevice->CreateOffscreenPlainSurface(imginfo.Width, imginfo.Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &Image, NULL)))

throw new char[] = "Cannot get surface'";

// First run image load

if (FAILED(D3DXLoadSurfaceFromFile(Image, NULL, NULL, (LPCWSTR) filename, NULL, D3DX_DEFAULT, NULL, NULL)))

throw new char[] = "Cannot load image from file";

// Get color info from the bottommost, leftmost pixel

tlrect.bottom = tlrect.top = imginfo.Height - 1;

tlrect.left = tlrect.right = imginfo.Width - 1;

if (FAILED(Image->LockRect(&lrect, &tlrect, D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY)))

throw new char[] = "Cannot read transparent color";

transparent = *((D3DCOLOR *) lrect.pBits);

if (FAILED(Image->UnlockRect()))

throw new char[] = "Cannot unlock rectangle";

// Seccond run image load

if (FAILED(D3DXLoadSurfaceFromFile(Image, NULL, NULL, (LPCWSTR) filename, NULL, D3DX_DEFAULT, transparent, NULL)))

throw new char[] = "Cannot load image from file";

}



Re: Game Technologies: DirectX 101 Undefined errorcode from D3DXGetImageInfoFromFile

Wessam Bahnassi

What does D3DX say in the debug output window when that function fails and what's the returned error code




Re: Game Technologies: DirectX 101 Undefined errorcode from D3DXGetImageInfoFromFile

petpan24

well, the debug says an exception is thrown and uncatched, errorcode i'll search for that one later

Some other bug to solve elswhere





Re: Game Technologies: DirectX 101 Undefined errorcode from D3DXGetImageInfoFromFile

petpan24

Got the errorcode: 0x88760b59 (hex, 32 bit)





Re: Game Technologies: DirectX 101 Undefined errorcode from D3DXGetImageInfoFromFile

Wessam Bahnassi

That error code is not undefined. Simply looking it up in DirectX Error Lookup shows:

HRESULT: 0x88760b59 (2289437529)
Name: D3DXERR_INVALIDDATA
Description: Invalid data
Severity code: Failed
Facility Code: FACILITY_D3D (2166)
Error Code: 0x0b59 (2905)

Such an error is usually accompanied by a helpful message from D3DX in the debug output window. Make sure you link against the debug version of D3DX first, and watch what is logged to the output window right as you step over that function.




Re: Game Technologies: DirectX 101 Undefined errorcode from D3DXGetImageInfoFromFile

petpan24

Thanks for the help, just have one last question, this linking against the debug Directx DLL, how do i do this, just cant find it anywhere.



Re: Game Technologies: DirectX 101 Undefined errorcode from D3DXGetImageInfoFromFile

Wessam Bahnassi

Check your linker options (Additional Dependencies option), and make sure you link against D3DX9D.lib instead of D3DX9.lib.




Re: Game Technologies: DirectX 101 Undefined errorcode from D3DXGetImageInfoFromFile

petpan24

Thanks, couldn't find that thing anywhere in the documentation

Edit: He cannot find those files , linker quits on it

Edit2: thought there was also a D3D9D.lib (there wasn't), got the problem, was very clear (The system can't find the given file)

Edit3: Just can't get it in a way in which dx wants to see the file, and don't get any clue why, just only can think of the conversion from char * to lpcwstr, but how to solve that one :
(source of caller may be usefull)

try

{

eng = new GraphEngine(hWindow);

res.Load("F:\test.bmp", eng);

fullinit = true;

}

catch (char)

{

return false;

}





Re: Game Technologies: DirectX 101 Undefined errorcode from D3DXGetImageInfoFromFile

petpan24

Solved, found how to do this with a simple function, was indeed that i needed to make an conversion from char * to LPCWSTR.