   loading a .x file
  I'm trying to load a mesh using a .x file that i made. It's based off the sdk tutorial since thats what im learning it from. I retyped it and try to make it so it only loads a mesh(instead of also applying a texture and rotating it). the program had 29 errors originally, but I managed to get it down to these six that i cant figure out.here is the errors:(45) : error C2664: 'D3DXLoadMeshFromXA' : cannot convert parameter 7 from 'DWORD' to 'DWORD *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast(49) : error C2065: 'd3dxMaterials' : undeclared identifier(56) : error C2065: 'd3dxMaterials' : undeclared identifier(56) : error C2228: left of '.MatD3D' must have class/struct/union(108) : error C2446: '<' : no conversion from 'D3DMATERIAL9 *' to 'DWORD'   There is no context in which this conversion is possible(108) : error C2040: '<' : 'DWORD' differs in levels of indirection from 'D3DMATERIAL9 *'here is the code://includes#include &lt;Windows.h&gt;#include &lt;mmsystem.h&gt;#include &lt;d3dx9.h&gt;//global variablesLPDIRECT3D9 d3d = NULL;LPDIRECT3DDEVICE9 d3d_device = NULL;LPD3DXMESH mesh = NULL;D3DMATERIAL9* materials = NULL;DWORD NumMaterials = NULL;//initialize functionHRESULT InitD3D(HWND hWnd){if(NULL == (d3d = Direct3DCreate9(D3D_SDK_VERSION)))return E_FAIL;D3DPRESENT_PARAMETERS d3dpp;ZeroMemory(&d3dpp, sizeof(d3dpp));d3dpp.Windowed = TRUE;d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;d3dpp.EnableAutoDepthStencil = TRUE;d3dpp.AutoDepthStencilFormat = D3DFMT_D16;if(FAILED(d3d-&gt;CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,  D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3d_device))){return E_FAIL;}d3d_device-&gt;SetRenderState(D3DRS_ZENABLE, TRUE);d3d_device-&gt;SetRenderState(D3DRS_AMBIENT, 0xffffffff);return S_OK;}HRESULT InitGeometry(){LPD3DXBUFFER buffer;if(FAILED(D3DXLoadMeshFromX("Cube.x", D3DXMESH_SYSTEMMEM,d3d_device, NULL, &buffer, NULL, NumMaterials, &mesh)))D3DXMATERIAL* d3dxMaterials;d3dxMaterials = ( D3DXMATERIAL* )buffer-&gt;GetBufferPointer();    materials = new D3DMATERIAL9[NumMaterials];    if( materials == NULL )   return E_OUTOFMEMORY;    for( DWORD i = 0; i &lt; NumMaterials; i++ )    {   materials = d3dxMaterials.MatD3D;   materials.Ambient = materials.Diffuse;}buffer-&gt;Release();return S_OK;}VOID Cleanup(){if(materials != NULL)delete[] materials;if( mesh != NULL )   mesh-&gt;Release();    if( d3d_device != NULL )   d3d_device-&gt;Release();    if( d3d != NULL )   d3d-&gt;Release();}VOID SetupMatrices(){    D3DXMATRIXA16 matWorld;    D3DXMatrixRotationY( &matWorld, timeGetTime() / 1000.0f );    d3d_device-&gt;SetTransform( D3DTS_WORLD, &matWorld );    D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f );    D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );    D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );    D3DXMATRIXA16 matView;    D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );    d3d_device-&gt;SetTransform( D3DTS_VIEW, &matView );    D3DXMATRIXA16 matProj;    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4, 1.0f, 1.0f, 100.0f );    d3d_device-&gt;SetTransform( D3DTS_PROJECTION, &matProj );}VOID Render(){d3d_device-&gt;Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0, 0, 225), 1.0f, 0); if(SUCCEEDED(d3d_device-&gt;BeginScene() ))    {   SetupMatrices();   for( DWORD i = 0; i &lt; materials; i++ )   {  d3d_device-&gt;SetMaterial( &materials );  mesh-&gt;DrawSubset( i );   }   d3d_device-&gt;EndScene();    }    d3d_device-&gt;Present( NULL, NULL, NULL, NULL );}LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ){    switch( msg )    {   case WM_DESTROY:  Cleanup();  PostQuitMessage( 0 );  return 0;    }    return DefWindowProc( hWnd, msg, wParam, lParam );}INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT ){ WNDCLASSEX wc =    {   sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,   GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,   "meshes", NULL    };    RegisterClassEx( &wc );    HWND hWnd = CreateWindow( "meshes", "meshes",WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,NULL, NULL, wc.hInstance, NULL );if( SUCCEEDED( InitD3D( hWnd ) ) )    {    if( SUCCEEDED( InitGeometry() ) )   {  ShowWindow( hWnd, SW_SHOWDEFAULT );  UpdateWindow( hWnd );    MSG msg;  ZeroMemory( &msg, sizeof( msg ) );  while( msg.message != WM_QUIT )  { if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) {TranslateMessage( &msg );DispatchMessage( &msg ); } elseRender();  }   }    }    UnregisterClass( "meshes", wc.hInstance );    return 0;}MOD EDIT: Added source tags[Edited by - Evil Steve on June 7, 2010 5:02:07 AM]
  In D3DXLoadMeshFromX(), you need to pass the address of NumMaterials:if(FAILED(D3DXLoadMeshFromX("Cube.x", D3DXMESH_SYSTEMMEM,d3d_device, NULL, &buffer, NULL, &NumMaterials, &mesh)))EDIT: Also, here:for( DWORD i = 0; i < materials; i++ )You probably meant to compare i to NumMaterials.[Edited by - Gage64 on June 5, 2010 10:28:44 AM];  For these errors:(108) : error C2446: '<' : no conversion from 'D3DMATERIAL9 *' to 'DWORD'There is no context in which this conversion is possible(108) : error C2040: '<' : 'DWORD' differs in levels of indirection from 'D3DMATERIAL9 *'You should probably changefor( DWORD i = 0; i < materials; i++ )tofor( DWORD i = 0; i < NumMaterials; i++ );  Ok, got those fixed 2 more errors.error C2065: 'd3dxMaterials' : undeclared identifierline: materials = d3dxMaterials.MatD3D;I declared it here im pretty sure:D3DXMATERIAL* d3dxMaterials = ( D3DXMATERIAL* )buffer->GetBufferPointer();error C2228: left of '.MatD3D' must have class/struct/unionline: materials = d3dxMaterials.MatD3D;I dont know if D3DXMATERIAL is one of those or not. does anyone know?;  I don't see why you're getting that error. Did you change anything else about the code? Are those the first errors that are listed?   ;  Here is the updated code://includes#include &lt;Windows.h&gt;#include &lt;mmsystem.h&gt;#include &lt;d3dx9.h&gt;//global variablesLPDIRECT3D9 d3d = NULL;LPDIRECT3DDEVICE9 d3d_device = NULL;LPD3DXMESH mesh = NULL;D3DMATERIAL9* materials = NULL;DWORD NumMaterials = NULL;//initialize functionHRESULT InitD3D(HWND hWnd){if(NULL == (d3d = Direct3DCreate9(D3D_SDK_VERSION)))return E_FAIL;D3DPRESENT_PARAMETERS d3dpp;ZeroMemory(&d3dpp, sizeof(d3dpp));d3dpp.Windowed = TRUE;d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;d3dpp.EnableAutoDepthStencil = TRUE;d3dpp.AutoDepthStencilFormat = D3DFMT_D16;if(FAILED(d3d-&gt;CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,  D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3d_device))){return E_FAIL;}d3d_device-&gt;SetRenderState(D3DRS_ZENABLE, TRUE);d3d_device-&gt;SetRenderState(D3DRS_AMBIENT, 0xffffffff);return S_OK;}HRESULT InitGeometry(){LPD3DXBUFFER buffer;if(FAILED(D3DXLoadMeshFromX("Cube.x", D3DXMESH_SYSTEMMEM,d3d_device, NULL, &buffer, NULL, &NumMaterials, &mesh))) D3DXMATERIAL* d3dxMaterials = ( D3DXMATERIAL* )buffer-&gt;GetBufferPointer();    materials = new D3DMATERIAL9[NumMaterials];    if( materials == NULL )   return E_OUTOFMEMORY;    for( DWORD i = 0; i &lt; NumMaterials; i++ )    {   materials = d3dxMaterials.MatD3D;   materials.Ambient = materials.Diffuse;}buffer-&gt;Release();return S_OK;}VOID Cleanup(){if(materials != NULL)delete[] materials;if( mesh != NULL )   mesh-&gt;Release();    if( d3d_device != NULL )   d3d_device-&gt;Release();    if( d3d != NULL )   d3d-&gt;Release();}VOID SetupMatrices(){    D3DXMATRIXA16 matWorld;    D3DXMatrixRotationY( &matWorld, timeGetTime() / 1000.0f );    d3d_device-&gt;SetTransform( D3DTS_WORLD, &matWorld );    D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f );    D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );    D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );    D3DXMATRIXA16 matView;    D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );    d3d_device-&gt;SetTransform( D3DTS_VIEW, &matView );    D3DXMATRIXA16 matProj;    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4, 1.0f, 1.0f, 100.0f );    d3d_device-&gt;SetTransform( D3DTS_PROJECTION, &matProj );}VOID Render(){d3d_device-&gt;Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0, 0, 225), 1.0f, 0); if(SUCCEEDED(d3d_device-&gt;BeginScene() ))    {   SetupMatrices();   for( DWORD i = 0; i &lt; NumMaterials; i++ )   {  d3d_device-&gt;SetMaterial( &materials );  mesh-&gt;DrawSubset( i );   }   d3d_device-&gt;EndScene();    }    d3d_device-&gt;Present( NULL, NULL, NULL, NULL );}LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ){    switch( msg )    {   case WM_DESTROY:  Cleanup();  PostQuitMessage( 0 );  return 0;    }    return DefWindowProc( hWnd, msg, wParam, lParam );}INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT ){ WNDCLASSEX wc =    {   sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,   GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,   "meshes", NULL    };    RegisterClassEx( &wc );    HWND hWnd = CreateWindow( "meshes", "meshes",WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,NULL, NULL, wc.hInstance, NULL );if( SUCCEEDED( InitD3D( hWnd ) ) )    {    if( SUCCEEDED( InitGeometry() ) )   {  ShowWindow( hWnd, SW_SHOWDEFAULT );  UpdateWindow( hWnd );    MSG msg;  ZeroMemory( &msg, sizeof( msg ) );  while( msg.message != WM_QUIT )  { if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) {TranslateMessage( &msg );DispatchMessage( &msg ); } elseRender();  }   }    }    UnregisterClass( "meshes", wc.hInstance );    return 0;}MOD EDIT: Added source tags[Edited by - Evil Steve on June 7, 2010 5:45:48 AM];  1. Please use [ source ] tags for pasting snippets of source code more than a few lines (I've edited them into your posts for you this time)2. I'd strongly recommend stepping back and learning C++ before jumping into DirectX. Otherwise you'll just keep getting stuck with bugs like these, and not be able to proceed until someone replies to help you.3. For the actual problem, you have the declaration of d3dxMaterials inside an if statement. Here's the same code, with braces added:if(FAILED(D3DXLoadMeshFromX("Cube.x", D3DXMESH_SYSTEMMEM,d3d_device, NULL, &buffer, NULL, &NumMaterials, &mesh))){   D3DXMATERIAL* d3dxMaterials = ( D3DXMATERIAL* )buffer->GetBufferPointer();}materials = new D3DMATERIAL9[NumMaterials];// ...You need something after the if() statement, probably return E_FAIL;:if(FAILED(D3DXLoadMeshFromX("Cube.x", D3DXMESH_SYSTEMMEM,d3d_device, NULL, &buffer, NULL, &NumMaterials, &mesh))){   return E_FAIL;}D3DXMATERIAL* d3dxMaterials = ( D3DXMATERIAL* )buffer->GetBufferPointer();materials = new D3DMATERIAL9[NumMaterials];// ...;  Sorry about about not using the code tags but could'nt find them. there probably in a obvious spot that I didn't see. I'm not use to direct x at all I guess they were all noob mistakes.   