Den här koden fungerar inte: Nu har jag lyckats lösa dom flesta problemen. Nu är problemet fixat!Problem med DirectX9
<code>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>
//*****Funktioner*****//
LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
void Render();
HRESULT InitD3D();
void CleanUp();
//*****Globala variabler*****//
IDirect3D9* g_pD3D;
IDirect3DDevice9* g_pD3DDevice;
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
{
//Regisrera window-klassen!
WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
"D3D", NULL};
RegisterClassEx(&wc);
//Skapa programfönstret!
HWND hWnd = CreateWindow("D3D", "D3D", WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
GetDesktopWindow(), NULL, wc.hInstance, NULL);
//Visa programfönstret!
ShowWindow(hWnd, SW_SHOWDEFAULT);
UpdateWindow(hWnd);
//Initiera Direct3D!
InitD3D();
//Meddelande-slinga
MSG msg;
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
Render();
}
}
}
//Händelsehanterare
LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_QUIT:
CleanUp();
return;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
HRESULT InitD3D()
{
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
#if DEBUG
{
d3dpp.Windowed = true;
}
#else
{
d3dpp.Windowed = false;
}
#endif
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferCount = 1;
g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if (g_pD3D == NULL)
{
return E_FAIL;
}
if (FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &g_pD3DDevice)))
{
return E_FAIL;
}
}
void CleanUp()
{
if (g_pD3D != NULL)
{
g_pD3D->Release();
}
}
void Render()
{
if (NULL == g_pD3DDevice)
return;
//Rensa skärmen!
g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
//Börja scenen!
g_pD3DDevice->BeginScene();
//Rendera här!
//Avsluta scenen!
g_pD3DDevice->EndScene();
//Visa scenen på skärmen!
g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
</code>
Felmeddelande:
1>------ Build started: Project: DirectX, Configuration: Debug Win32 ------
1>Compiling...
1>DirectX.cpp
1>h:\programmering\visual c++ 2005\directx\directx\directx.cpp(23) : error C2440: 'initializing' : cannot convert from 'const char [4]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>h:\programmering\visual c++ 2005\directx\directx\directx.cpp(28) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [4]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>h:\programmering\visual c++ 2005\directx\directx\directx.cpp(63) : error C2561: 'MsgProc' : function must return a value
1> h:\programmering\visual c++ 2005\directx\directx\directx.cpp(9) : see declaration of 'MsgProc'
1>h:\programmering\visual c++ 2005\directx\directx\directx.cpp(94) : error C2065: 'hWnd' : undeclared identifier
1>Build log was saved at "file://h:\Programmering\Visual C++ 2005\DirectX\DirectX\Debug\BuildLog.htm"
1>DirectX - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Vad är det som är fel?
/MagnusSv: Problem med DirectX9
Nu får jag bara två felmeddelanden:
1>------ Build started: Project: DirectX, Configuration: Debug Win32 ------
1>Compiling...
1>DirectX.cpp
1>h:\programmering\visual c++ 2005\directx\directx\directx.cpp(39) : warning C4700: uninitialized local variable 'msg' used
1>Linking...
1>LINK : fatal error LNK1104: cannot open file 'uuid.lib'
1>Build log was saved at "file://h:\Programmering\Visual C++ 2005\DirectX\DirectX\Debug\BuildLog.htm"
1>DirectX - 1 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========Sv:Problem med DirectX9
Jag hade glömt att göra några inställningar.
/Magnus