Jump to content

  • Log In with Google      Sign In   
  • Create Account

HR Instance not found


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 musicon   Members   -  Reputation: 110

Like
0Likes
Like

Posted 21 November 2011 - 02:20 PM

I am trying the first demo exercise in Luna's Intro to DirectX 9 Shader Approach (all I can run on current computer) Here I have so far

#include <iostream>
#include <string.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dUtil.h>
#include <d3dApp.h>
#include <tchar.h>
#include <DxErr.h>
#include <crtdbg.h>

using namespace std;


class HelloD3DApp : public D3DApp
{
public:
	HelloD3DApp(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP);
	~HelloD3DApp();

	bool checkDeviceCaps();
	void onLostDevice();
	void onResetDevice();
	void updateScene(float dt);
	void drawScene();

private:
	ID3DXFont* mFont;
};

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)

{
	// enable runtine memory chack for debug builds
#if defined(DEBUG) | defined(_DEBUG)_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

	HelloD3DApp app(hInstance, "Hello Direct3D", D3DDEVTYPE_HAL, D3DCREATE_HARDWARE_VERTEXPROCESSING);
	gd3dApp = &app;

	return gd3dApp->run();
}

HelloD3DApp::HelloD3DApp(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
	: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	HRESULT DXTrace(CHAR *strFile, DWORD dwline, HRESULT hr, CHAR *strMsg, BOOL bPopMsgBox);
	srand(time_t(0));

	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed() Failed", 0, 0);
		PostQuitMessage(0);
	}

	D3DXFONT_DESC fontDesc;
	fontDesc.Height = 80;
	fontDesc.Width = 40;
	fontDesc.Weight = FW_BOLD;
	fontDesc.MipLevels = 0;
	fontDesc.Italic = true;
	fontDesc.CharSet = DEFAULT_CHARSET;
	fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS;
	fontDesc.Quality = DEFAULT_QUALITY;
	fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
	_tcscpy(fontDesc.FaceName, _T("Times New Roman"));

	HR(D3DXCreateFontIndirect(gd3dDevice, &fontDesc, &mFont));
}

HelloD3DApp::~HelloD3DApp()
{
	ReleaseCOM(mFont);
}

#define ReleaseCOM(x) {if(x) {x->Release();x = 0; } }

bool HelloD3DApp::checkDeviceCaps()
{
	return true;
}

void HelloD3DApp::updateScene(float dt)
{
}

void HelloD3DApp::onLostDevice()
{
	HR(mFont->OnLostDevice());
}
void HelloD3DApp::onResetDevice()
{
	HR(mFont->OnResetDevice());
}

void HelloD3DApp::drawScene()
{
	HR(gd3dDevice->Clear(0,0,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0F, 0));

	RECT formatRect;
	GetClientRect(mhMainWnd, &formatRect);

	HR(gd3dDevice->BeginScene());

	mFont->DrawTextA(0, _T("Hello Direct3D"), -1, &formatRect, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(rand()% 256, rand() % 256, rand() % 256));

	HR(gd3dDevice->EndScene());
	HR(gd3dDevice->Present(0,0,0,0,));
}

HRESULT IDirect3DDevice9::Clear(
	DWORD Count, const D3DRECT* pRects,
	DWORD Flags, D3DCOLOR Color,
	float Z,
	DWORD Stencil);

INT ID3DXFont::DrawTextA(
	LPD3DXSPRITE pSprite,
	LPCTSTR pString,
	INT Count,
	LPRECT pRect,
	DWORD Format,
	D3DCOLOR Color);

Quite a few issues but mostly it is the HR not recognised that is causing problems. I am using VC++ 2010 and think I have done all the linking required but what specifically is causing the HR (HRESULT?) error?

Sponsor:

#2 kaykry   Members   -  Reputation: 111

Like
0Likes
Like

Posted 22 November 2011 - 09:57 PM

I'm not sure I understand your question but maybe this will help. If you look in the file d3dUtil.h you will see that HR is a macro defined as:

#if defined(DEBUG) | defined(_DEBUG)
	#ifndef HR
	#define HR(x)                                  	\
	{                                              	\
		HRESULT hr = x;                            	\
		if(FAILED(hr))                             	\
		{                                          	\
			DXTrace(__FILE__, __LINE__, hr, #x, TRUE); \
		}                                          	\
	}
	#endif

#else
	#ifndef HR
	#define HR(x) x;
	#endif
#endif


#3 MyPlumbing   Members   -  Reputation: 100

Like
0Likes
Like

Posted 23 November 2011 - 12:02 AM

I feel your work, and blog, are great.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS