Page 1 of 1

LNK2019: unresolved external symbol __imp___CrtDbgReportW

Posted: Thu Mar 17, 2011 5:23 am
by RandomDever
Why is it giving me this error?

Code: Select all

LNK2019: unresolved external symbol __imp___CrtDbgReportW

Re: LNK2019: unresolved external symbol __imp___CrtDbgReportW

Posted: Thu Mar 17, 2011 6:29 am
by Milch
Well, obviously you didn't link something that is needed.
Give more information and maybe somebody can help you ;)

Re: LNK2019: unresolved external symbol __imp___CrtDbgReportW

Posted: Thu Mar 17, 2011 7:05 am
by Boogy

Re: LNK2019: unresolved external symbol __imp___CrtDbgReportW

Posted: Thu Mar 17, 2011 7:48 pm
by RandomDever
@Boogy: Thanks it worked.
Now I'm having problems with this:

Code: Select all

keystates = SDL_GetKeyState( NULL );
It keeps giving me an error:

Code: Select all

Access violation reading location 0xcccccccc

Re: LNK2019: unresolved external symbol __imp___CrtDbgReportW

Posted: Thu Mar 17, 2011 9:19 pm
by Falco Girgis
...You can't just show us a line of code that is syntactically correct then show us an error. Obviously that's not enough information. =/

Re: LNK2019: unresolved external symbol __imp___CrtDbgReportW

Posted: Thu Mar 17, 2011 10:25 pm
by RandomDever
GyroVorbis wrote:...You can't just show us a line of code that is syntactically correct then show us an error. Obviously that's not enough information. =/
I apologize.

Here's the header:

Code: Select all

class Input
{
public:
	void Init();
	int Poll();
	bool Type( Uint8 type );
	SDL_Event *Get();
	Uint8 GetKey( int key, int check = INPUT_ISDOWN );
	int GetMouse( int button, int check = INPUT_ISDOWN );
private:
	SDL_Event event;
	Uint8 *keystates;
	bool keyEvents[322][2];
	int mousestates[3];
	bool mouseEvents[3][2];
};
And here's the CPP file:

Code: Select all

void Input::Init()
{
	keystates = SDL_GetKeyState( NULL );
	mousestates[0] = false;
	mousestates[1] = false;
	mousestates[2] = false;
	for( int i = 0; i < 322; i++ )
	{
		keyEvents[i][0] = false;
		keyEvents[i][1] = false;
	}
}

int Input::Poll()
{
	SDL_PumpEvents();
	for( int i = 0; i < 322; i++ )
	{
		keyEvents[i][0] = keyEvents[i][1];
		if( keystates[i] == 0 )
		{
			keyEvents[i][1] = false;
		}
		else
		{
			keyEvents[i][1] = true;
		}
	}

	mousestates[0] = SDL_GetMouseState( NULL, NULL ) & SDL_BUTTON( 1 );
	mousestates[1] = SDL_GetMouseState( NULL, NULL ) & SDL_BUTTON( 2 );
	mousestates[2] = SDL_GetMouseState( NULL, NULL ) & SDL_BUTTON( 3 );
	for( int i = 0; i < 3; i++ )
	{
		mouseEvents[i][0] = mouseEvents[i][1];
		if( mousestates[i] == 0 )
		{
			mouseEvents[i][1] = false;
		}
		else
		{
			mouseEvents[i][1] = true;
		}
	}

	return SDL_PollEvent( &event );
}

bool Input::Type( Uint8 type )
{
	return event.type == type;
}

SDL_Event *Input::Get()
{
	return &event;
}

Uint8 Input::GetKey( int key, int check )
{
	if( check == INPUT_RELEASE )
	{
		if( keyEvents[key][0] == true && keyEvents[key][1] == false )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else if( check == INPUT_PRESS )
	{
		if( keyEvents[key][0] == false && keyEvents[key][1] == true )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	return keystates[key];
}

int Input::GetMouse( int button, int check )
{
	if( check == INPUT_RELEASE )
	{
		if( mouseEvents[button][0] == true && mouseEvents[button][0] == false )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else if( check == INPUT_PRESS )
	{
		if( mouseEvents[button][0] == false && mouseEvents[button][0] == true )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	return mousestates[button - 1];
}
Here's the additional dependencies:

Code: Select all

SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib  OpenGL32.lib glu32.lib

Re: LNK2019: unresolved external symbol __imp___CrtDbgReportW

Posted: Fri Mar 18, 2011 3:25 am
by Boogy
Have you initialized SDL before calling SDL_GetKeyState()?

And are you running in debug mode because release can produce different result

Re: LNK2019: unresolved external symbol __imp___CrtDbgReportW

Posted: Fri Mar 18, 2011 7:48 am
by RandomDever
@Boogy: No and yes.
Oops.
Thanks again.

Re: LNK2019: unresolved external symbol __imp___CrtDbgReportW

Posted: Fri Mar 18, 2011 7:49 am
by N64vSNES
Boogy wrote:Have you initialized SDL before calling SDL_GetKeyState()?

And are you running in debug mode because release can produce different result
This^

And here:

Code: Select all

int Input::GetMouse( int button, int check )
What if button is 0?
Then here:

Code: Select all

return mousestates[button - 1];
You return the index -1 in the array, this should spring a access violation.