Sign in to follow this  

[SOLVED]__security_cookie + Access Violation(5th post)

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

Hello, I used the following code to try and initialize a LPD3DXSprite and got 67 Linker errors regarding and unresolved symbol - __security_cookie and other similar ones.
#include <windows.h>
#include <d3d9.h>
#include <d3dx9core.h>

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib,"d3dx9.lib")

//Globals
LPDIRECT3D9 lpd3d9;
LPDIRECT3DDEVICE9 lpd3dd9;
LPD3DXSPRITE sprite;

char lpClassName[] = "CampAdv";

HRESULT Init3D(HWND hWnd)
{
	lpd3d9 = Direct3DCreate9(D3D_SDK_VERSION);
	D3DPRESENT_PARAMETERS d3dpp;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	d3dpp.Windowed = true;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;

	if (!lpd3d9->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp, &lpd3dd9))
	{
		MessageBox(hWnd, "Error creating Device","Error",MB_OK);
		return E_FAIL;
	}
	if(!D3DXCreateSprite(lpd3dd9,&sprite))
	{
		MessageBox(hWnd, "Error creating Sprite","Error",MB_OK);
		return E_FAIL;
	}
	return S_OK;
}

void Render()
{
	if (sprite->Begin(D3DXSPRITE_ALPHABLEND))
	{
		sprite->End();
	}
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_PAINT:
		Render();
		return 0;
		break;
	default:
		return DefWindowProc(hWnd,msg,wParam,lParam);
	    break;
	}
	return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
				   LPSTR lpCmdLine, int nShowCmd)
{
	WNDCLASSEX wc;
	HWND hWnd;
	MSG msg;

	wc.cbClsExtra	= 0;
	wc.cbSize		= sizeof(WNDCLASSEX);
	wc.cbWndExtra	= 0;
	wc.hbrBackground= (HBRUSH)(COLOR_WINDOW);
	wc.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wc.hIcon		= LoadIcon(NULL,IDI_APPLICATION);
	wc.hIconSm		= wc.hIcon;
	wc.hInstance	= hInstance;
	wc.lpfnWndProc	= WndProc;
	wc.lpszClassName= lpClassName;
	wc.lpszMenuName	= NULL;
	wc.style		= 0;

	if (!RegisterClassEx(&wc))
	{
		MessageBox(NULL,"Error Registering ClassEx","Error",MB_OK);
		return 0;
	}
	hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,lpClassName,"Main Window",
		WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 300,300,NULL,
		NULL, hInstance, NULL);
	if (!hWnd)
	{
		MessageBox(NULL, "Error creating window","Error",MB_OK);
		return 0;
	}

	if (FAILED(Init3D(hWnd)))
	{
		return 0;
	}
	ShowWindow(hWnd,nShowCmd);
	UpdateWindow(hWnd);

	while (GetMessage(&msg,hWnd,0,0) > 0)
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}

[Edited by - brwarner on June 11, 2006 5:17:04 PM]

Share this post


Link to post
Share on other sites
Which compiler are you using, and which version of the DirectX SDK? Some older compilers are incompatible with recent versions of the SDK and produce error messages like you've described.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Which compiler are you using, and which version of the DirectX SDK? Some older compilers are incompatible with recent versions of the SDK and produce error messages like you've described.

IIRC, this can specifically happen if you try to compile with any semi-recent SDKs (ie since April 2005 I think) with Visual Studio 6.

Share this post


Link to post
Share on other sites
I am having a problem again. I used the Summer 2003 version of the SDK with the same code as above. It compiles without errors but I get an Access Violation at the point where it says sprite->Begin(..).
What is causing this access violation.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
You never create the sprite object, so the pointer is invalid when you try calling Begin() on it.


didnt i create it at:

if(!D3DXCreateSprite(lpd3dd9,&sprite))
{
...
}




EDIT: Woops I didnt call Init3D. See above for improved source code - still access violation.

Share this post


Link to post
Share on other sites
if(!D3DXCreateSprite(lpd3dd9,&sprite))
{
MessageBox(hWnd, "Error creating Sprite","Error",MB_OK);
return E_FAIL;
}

Just a quick thing - whenever testing HRESULTs, always use the SUCCEEDED() or FAILED() macros. This is because a A zero or larger HRESULT value indicates a successful scenario, while a negative value indicates an unsuccessful scenario. Your code should be:

if(FAILED(D3DXCreateSprite(lpd3dd9,&sprite)))
{
MessageBox(hWnd, "Error creating Sprite","Error",MB_OK);
return E_FAIL;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by brwarner
Thanks, that narrowed it down to an error creating the device,

If you haven't already, check the debug runtime output - this will tell you exactly why it is failing. If you haven't used the debug runtimes before, there is a good section on it in the DirectX FAQ.

Share this post


Link to post
Share on other sites

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