#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;
}
[SOLVED]__security_cookie + Access Violation(5th post)
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.
[Edited by - brwarner on June 11, 2006 5:17:04 PM]
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.
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.
I was using Visual Studio 6 with October 2004. Im bumping back to Summer 2003 and seeing what happens.
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.
What is causing this access violation.
You never create the sprite object, so the pointer is invalid when you try calling Begin() on it.
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.
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;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement