Direct-X Intialisierungsproblem

bluescreen
Also ich hab versuch einfach nur einen D3DDevice anzulegen und zu Intialisieren,
doch mein Linker gibt nen Fehler. An der Installation von Direct-X liegts nich, denn ich hab schon andere 2D Programm realisiert und die gingen.
Also, der Code:
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
#define STRICT
#include <d3d9.h>
#include <d3dx9.h>
#include <windows.h>

//Callbackfunktion
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//Direct-X Funktionen
void init();
void shutDown();
//DIRECT_X
LPDIRECT3D9       lp3DO       = NULL;
LPDIRECT3DDEVICE9 lpDevice = NULL;
//WIN_API
HWND			hWnd;
MSG			mMsg;
WNDCLASS	wndClass;

int WINAPI WinMain(	HINSTANCE hInstance, HINSTANCE hPrevInstance,
					LPSTR lpCmdLine, int nCmdShow)//Hauptfunktion
{

	//beschreiben der wndClass
	wndClass.hCursor        = LoadCursor(hInstance, IDC_HAND); 
	wndClass.hIcon          = LoadIcon(hInstance, IDI_HAND); 
	wndClass.lpszMenuName   = NULL; 
	wndClass.lpszClassName  = "d3dDevice"; 
	wndClass.hbrBackground  = (HBRUSH)GetStockObject(BLACK_BRUSH); 
	wndClass.hInstance      = hInstance; 
	wndClass.style          = CS_VREDRAW | CS_HREDRAW ;
	wndClass.lpfnWndProc    = WndProc; 
	wndClass.cbWndExtra     = 0; 
	wndClass.cbClsExtra     = 0; 
	//ende - wndClass

	RegisterClass(&wndClass);

	hWnd = CreateWindow("d3dDevice", "d3dDevice", WS_OVERLAPPEDWINDOW,
						50, 50, 1024, 765, NULL, NULL, hInstance, NULL);

	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);
	init();

	//MessageBox
	MessageBox(hWnd, "yo... es geht!", "Test", MB_OK);

	//Messaging-system
	while(GetMessage(&mMsg, NULL, 0, 0))
	{
		TranslateMessage(&mMsg);
		DispatchMessage(&mMsg);
	}
	
	shutDown();
	return mMsg.wParam;
}
  

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_DESTROY: 
		{
			PostQuitMessage(0);
			return 0;
		}
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}
		
void init()
{
	//Direct3D9-Objekt anlegen
	lp3DO = Direct3DCreate9( D3D_SDK_VERSION );
	//Devicezeiger anlegen
	LPDIRECT3DDEVICE9 lpDevice = NULL;
	//Presenparameterszeiger anlegen
	D3DPRESENT_PARAMETERS d3Dpp;
	ZeroMemory(&d3Dpp, sizeof(d3Dpp));
	//Windowmodus setzen
	d3Dpp.Windowed = TRUE;
	//Swap-Effect setzen
	d3Dpp.SwapEffect = D3DSWAPEFFECT_COPY;

	//Device erzeugen
	lp3DO->CreateDevice( D3DADAPTER_DEFAULT,
						 D3DDEVTYPE_HAL, hWnd,
						 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3Dpp, &lpDevice);
	return;
}

void shutDown()
{
    if( lpDevice != NULL )
	{
        lpDevice->Release();
	}

    if( lp3DO != NULL )
	{
        lp3DO->Release();
	}
}


und der Fehler (ich benutze VC++ 200cool :
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
1>------ Erstellen gestartet: Projekt: d3ddevice, Konfiguration: Debug Win32 ------
1>Kompilieren...
1>main.cpp
1>Verknüpfen...
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol   "_Direct3DCreate9@4" in Funktion ""void __cdecl init(void)" (?init@@YAXXZ)".

1>C:\Users\Nicolas\Documents\Visual Studio 2008\Projects\d3ddevice\Debug\d3ddevice.exe : fatal error LNK1120: 1 nicht aufgelöste externe Verweise.

1>Das Buildprotokoll wurde unter "file://c:\Users\Nicolas\Documents\Visual Studio 2008\Projects\d3ddevice\d3ddevice\Debug\BuildLog.htm" gespeichert.

1>d3ddevice - 2 Fehler, 0 Warnung(en)
===== =Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ======

was meint der?
ThiefMaster
DAnn hast du wohl die directx-Libs nict bei den Linkeroptionen eingetragen.
bluescreen
hmm...
Das kann sein. Ich schau mal.
bluescreen
ne
eigentlich nicht. Ich hab in den VC++ Einstellungen einen Eintrag
code:
1:
2:
3:
C:\Program Files\Microsoft DirectX SDK (August 2006)\Lib\x86
bluescreen
lol...
ich Depp. Natürlich, du meinst in den Projekteinstellungen. Du hattest recht. Ich habs vergessen. Funktioniert. Danke
bluescreen
Ich fahre mit meinem DirectX tut fort... und hab schon wieder Problem.
Ich hab mir überlegt ob ich nen neuen Thread machen soll, aber ich glaube es ist ja fast das selbe, also schreib ich wieder in diesen:
Also, ich möchte einfach nur en PointLight in meine Programm erzeugen, wobei ich mir nicht licher bin, ob ich das einfach ohne Viewport kann (Das Buch ist ein bischen ungenau, es behandelt nur die DX-funktionen allgemein). Das übersetzen klappt auch,
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
#define STRICT
#include <d3d9.h>
#include <d3dx9.h>
#include <windows.h>

//Callbackfunktion
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//Direct-X Funktionen
void init();
void shutDown();
void setPointLight();
//DIRECT_X
LPDIRECT3D9       lp3DO       = NULL;
LPDIRECT3DDEVICE9 lpDevice = NULL;
//WIN_API
HWND			hWnd;
MSG			mMsg;
WNDCLASS	wndClass;

int WINAPI WinMain(	HINSTANCE hInstance, HINSTANCE hPrevInstance,
					LPSTR lpCmdLine, int nCmdShow)//Hauptfunktion
{

	//beschreiben der wndClass
	wndClass.hCursor        = LoadCursor(hInstance, IDC_HAND); 
	wndClass.hIcon          = LoadIcon(hInstance, IDI_HAND); 
	wndClass.lpszMenuName   = NULL; 
	wndClass.lpszClassName  = "d3dDevice"; 
	wndClass.hbrBackground  = (HBRUSH)GetStockObject(BLACK_BRUSH); 
	wndClass.hInstance      = hInstance; 
	wndClass.style          = CS_VREDRAW | CS_HREDRAW ;
	wndClass.lpfnWndProc    = WndProc; 
	wndClass.cbWndExtra     = 0; 
	wndClass.cbClsExtra     = 0; 
	//ende - wndClass

	RegisterClass(&wndClass);

	hWnd = CreateWindow("d3dDevice", "d3dDevice", WS_OVERLAPPEDWINDOW,
						50, 50, 1024, 765, NULL, NULL, hInstance, NULL);

	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);
	init();
	setPointLight();

	//MessageBox
	MessageBox(hWnd, "yo... es geht!", "Test", MB_OK);

	//Messaging-system
	while(GetMessage(&mMsg, NULL, 0, 0))
	{
		TranslateMessage(&mMsg);
		DispatchMessage(&mMsg);
	}
	
	shutDown();
	return mMsg.wParam;
}
  

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_DESTROY: 
		{
			PostQuitMessage(0);
			return 0;
		}
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}
		
void init()
{
	//Direct3D9-Objekt anlegen
	lp3DO = Direct3DCreate9( D3D_SDK_VERSION );
	//Devicezeiger anlegen
	LPDIRECT3DDEVICE9 lpDevice = NULL;
	//Presenparameterszeiger anlegen
	D3DPRESENT_PARAMETERS d3Dpp;
	ZeroMemory(&d3Dpp, sizeof(d3Dpp));
	//Windowmodus setzen
	d3Dpp.Windowed = TRUE;
	//Swap-Effect setzen
	d3Dpp.SwapEffect = D3DSWAPEFFECT_COPY;

	//Device erzeugen
	lp3DO->CreateDevice( D3DADAPTER_DEFAULT,
						 D3DDEVTYPE_HAL, hWnd,
						 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3Dpp, &lpDevice);
	return;
}

void shutDown()
{
    if( lpDevice != NULL )
	{
        lpDevice->Release();
	}

    if( lp3DO != NULL )
	{
        lp3DO->Release();
	}
}

void setPointLight()
{
	//D3DLight erzeugen
	D3DLIGHT9 d3DLight;
	ZeroMemory(&d3DLight, sizeof(d3DLight));
	//Lichttyp
	d3DLight.Type = D3DLIGHT_POINT;
	//Farbwerte
	d3DLight.Diffuse.r = 1.0f;
	d3DLight.Diffuse.g = 1.0f;
	d3DLight.Diffuse.b = 1.0f;

	d3DLight.Ambient.r = 1.0f;
	d3DLight.Ambient.g = 1.0f;
	d3DLight.Ambient.b = 1.0f;

	d3DLight.Specular.r = 1.0f;
	d3DLight.Specular.g = 1.0f;
	d3DLight.Specular.b = 1.0f;
	//Lichtposition
	d3DLight.Position.x = 0.0f;
	d3DLight.Position.y = 1000.0f;
	d3DLight.Position.z = -100.0f;
	//attenuation
	d3DLight.Attenuation0 = 1.0f;
	//Lichtausdehnung
	d3DLight.Range = 1000.0f;
	//Licht setzen
	lpDevice->SetLight(0, &d3DLight);
}

aber bei der ausführung(Debugen) kommt folgende Meldung:
code:
1:
2:
3:
Unbehandelte Ausnahme bei 0x00f51995 in d3ddevice.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x00000000.

und die vorletzte zeile
code:
1:
2:
3:
	lpDevice->SetLight(0, &d3DLight);

wird als fehlerquelle angegeben.
Jetzt würd ich gern wissen:
- 1. Was mach ich falsch?
- 2. Ist das überhaupt richtig, oder muss da noch "weiterlesen" bis ich noch andere
Funktionen hab?

Freu mich auf Anworten
Hanfling
Liegt es vielleicht daran, weil du mit D3DLIGHT9 d3DLight; das auf dem Stack erzeugst und es gelöscht wird sobald die funktion beended wird?
bluescreen
hm
stimmt, daran hab ich nicht gedacht...
aber ich hab auch schon probiert das ganze statt in einer funktion direkt in den Code zu schreiben. Da tritt genau das gleiche Problem auf
Hanfling
Musst du evtl. eher mit malloc / new dafür Speicher beschaffen und geht es dann?
bluescreen
was is malloc?
ne funktion ?
und mit new... ja gut ich teste es mal
Hanfling