I used this code from a book to initialize a window with direct x 8 and copied it EXACTLY. i looked over every line of the code from the cd and it is exact(except for the source file comments but that doesnt matter). WTF is wrong with it!? It says unresolved external Direct3DCreate8@4 but after GameInit() i established it as a global pointer. It compiles with the books code and not with mine. i even looked to see if they had any header files that i didnt or if they had anything in the folder i didnt but they didnt. So whats wrong?(this happens almost every time i try to copy it from the book)
------------------------------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <mmsystem.h>
#include <d3d8.h>
#include <d3dx8.h>
int GameInit();
int GameLoop();
int GameShutdown();
void SetError( char* String );
LPDIRECT3D8 g_pD3D = 0;
LPDIRECT3DDEVICE8 g_pDevice = 0;
HWND g_hWndMain;
void SetError( char* String )
{
OutputDebugString( String );
OutputDebugString( "\n" );
}
long CALLBACK WndProc( HWND hWnd, UINT uMessage,
WPARAM wParam, LPARAM lParam )
{
switch( uMessage )
{
case WM_CREATE:
{
return 0;
}
case WM_PAINT:
{
ValidateRect( hWnd, NULL);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage( 0 );
return 0;
}
default:
{
return DefWindowProc( hWnd, uMessage, wParam, lParam );
}
}
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR pstrCmdLine, int iCmdShow )
{
HWND hWnd;
MSG msg;
WNDCLASSEX wc;
static char strAppName[] = "First Windows App, Zen Style";
wc.cbSize = sizeof( WNDCLASSEX );
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)GetStockObject( DKGRAY_BRUSH );
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_CROSS );
wc.lpszMenuName = NULL;
wc.lpszClassName = strAppName;
RegisterClassEx( &wc );
hWnd = CreateWindowEx( NULL,
strAppName,
strAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
512,512,
NULL,
NULL,
hInstance,
NULL);
g_hWndMain = hWnd;
ShowWindow( hWnd, iCmdShow );
UpdateWindow( hWnd );
if( FAILED( GameInit() ) )
{
SetError( "Initialization Failed" );
GameShutdown();
return E_FAIL;
}
while( TRUE )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if( msg.message == WM_QUIT )
break;
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
GameLoop();
}
}
GameShutdown();
return msg.wParam;
}
int GameInit()
{
HRESULT r = 0;
D3DDISPLAYMODE d3ddm;
D3DPRESENT_PARAMETERS d3dpp;
g_pD3D = Direct3DCreate8( D3D_SDK_VERSION );
if( g_pD3D == NULL )
{
SetError( "Cold not create IDirect3D8 object" );
return E_FAIL;
}
r = g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT,
&d3ddm );
if( FAILED( r ) )
{
SetError( "Could not get display adapter information" );
return E_FAIL;
}
ZeroMemory( &d3dpp, sizeof( D3DPRESENT_PARAMETERS ) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
r = g_pD3D->CreateDevice( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
g_hWndMain,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&g_pDevice );
if( FAILED( r ) )
{
SetError( "Could not create the render device" );
return E_FAIL;
}
return S_OK;
}
int GameLoop()
{
return S_OK;
}
int GameShutdown()
{
if(g_pDevice )
{
g_pDevice->Release();
g_pD3D = 0;
}
if( g_pD3D )
{
g_pD3D->Release();
g_pD3D = 0;
}
return S_OK;
}
------------------------------------------------------------------------------------------------
moved to DirectX. do you have the direct x sdk? if you dont thats probly why its not working. if you do then i duno.
The DXSDK was probably included with his book. Anyway he should be including a few libraries like d3d8.lib or whatever it's called. If you want just include all of the libraries in the <dxsdkdir>\lib directory.
Unresolved externals are caused by missing links.
Assuming you are using Microsoft C++ Visual Studio, everytime you make a project set the Project settings/Link/Object/library modules to the lib files.(dxguid.lib d3d8.lib d3dx8.lib winmm.lib)
Also make sure your IDE directories list includes the SDK path and should first on the list. Tools/Options/Directories.
good luck
As an alternative you can use
| CODE |
#pragma comment(lib, "d3d8.lib")
|
You could also scrue the whole "direct3dcerate" and go pure com. CoCreateInstance baby!