   A little Sintax problem..
  I've writed this two functions:LoadMesh():LPD3DXMESH dxManager::loadMesh(std::string filename){HRESULT hr;LPD3DXMESH tempMesh;LPD3DXBUFFER ppAdjacencyBuffer;LPD3DXBUFFER pD3DXMtrlBuffer = NULL;tempMesh = NULL;    // Load the mesh from the specified file    hr = D3DXLoadMeshFromX( filename.c_str(), D3DXMESH_SYSTEMMEM, pd3dDevice,    &ppAdjacencyBuffer, &pD3DXMtrlBuffer, NULL,   &m_dwNumMaterials, &tempMesh );    if( FAILED(hr) )return NULL;D3DXMATERIAL* matMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();   //Create two arrays. One to hold the materials and only to hold the textures    m_pMeshMaterials = new D3DMATERIAL9[m_dwNumMaterials];   for(DWORD i = 0; i < m_dwNumMaterials; i++)    {   //Copy the material   m_pMeshMaterials = matMaterials.MatD3D;   //Set the ambient color for the material (D3DX does not do this)   m_pMeshMaterials.Ambient = m_pMeshMaterials.Diffuse;    }return tempMesh;}void dxManager::drawMesh(LPD3DXMESH pMesh, D3DXVECTOR3 position){    D3DXMATRIX matPos;D3DXMATRIX meshMatrix, scaleMatrix, rotateMatrix;D3DXMatrixTranslation(&matPos, position.x, position.y, position.z);createCamera(1.0f, 750.0f);// near clip plane, far clip planemoveCamera(D3DXVECTOR3(0.0f, 0.0f, -450.0f));pointCamera(D3DXVECTOR3(0.0f, 0.0f, 0.0f));// set the rotationD3DXMatrixRotationY(&rotateMatrix, timeGetTime()/1000.0f);// set the scalingD3DXMatrixScaling(&scaleMatrix, 0.5f, 0.5f, 0.5f);// multiple the scaling and rotation matrices to create the meshMatrixD3DXMatrixMultiply(&meshMatrix, &scaleMatrix, &rotateMatrix);// multiple the scaling and rotation matrices to create the meshMatrixD3DXMatrixMultiply(&meshMatrix, &matPos, &meshMatrix);// transform the object in world spacepd3dDevice->SetTransform(D3DTS_WORLD, &meshMatrix);for(DWORD i = 0; i < m_dwNumMaterials; i++){pd3dDevice->SetMaterial(&m_pMeshMaterials);    pMesh->DrawSubset(i);}}When i try to call the function:mesh1 = dxMgr->loadMesh("Dolphin1.x");if (!mesh1){MessageBox(wndHandle, "can't load xfile", "ERROR", MB_OK);return false;}And when i try to run my program, my exe can't load the Mesh. I put my .x file in the directory of .exe file. But when i try to run the program, it give me the Error "can't load xfile". It's that a syntax error?(Sorry for my bad english).   
  A syntax error is when the data is not in the expected format -- for example writing BEGIN and END in a C++ program (yes without any funky ifdef constructs). It could be that the x file is not in the right format but this is usually not the case.In this case it seems that either the file is not found at all or it is not in the right format. Check if it is found by specifying the full path (including drive letter). Also be wary of VS because it uses a different current directory from where your program actually is.Alternatively, try opening the file with some DX viewer to see if it is in a correct x-file format.For the rest, check your return codes and step through the program and see where it fails. Its hard to tell from here.Illco   ;  I suppose youre using visual studio since youre using directx. When executing apps from within vs (with the run command etc) the program will not be executed in the debug directory (or wherever your exe is). It will be executed from the project directory (where you usually have all your source-code files). Thus in this case your app wouldnt find the x-file. Try running the exe from windows explorer (or place your x-file in the project directory). If it still doesnt work, then something is probably wrong with your code or the file itself.//Emil   ;  Purely as a case of good programming practice, fragments like:if( FAILED( hr ) ) return NULL;Aren't really of that much use. In your function there is only one (thus your error is almost certainly due to D3DXLoadMeshFromX() failing) but as your code gets bigger it actually slows debugging down.Something like:hr = // some functionif( FAILED( hr ) ){    #ifdef DEBUG   // Only include heavy-weight debugging information   // for the debugging builds...   std::wostringstream woss;   woss << L"Error occurred whilst calling "   << __FUNCTION__   << L" in "   << __FILE__   << L" on line number "   << __LINE __   << ".\n";   OutputDebugString( woss.str().c_str() );    #endif    return hr; // return the code (not NULL) so the caller can check it}else{    #if HARDCORE_DEBUG_AND_TRACE_ENABLED   std::wostringstream woss;   woss << L"Function ("   << __FUNCTION__   << L") succeeded at line number "   << __LINE__   << ".\n";   OutputDebugString( woss.str().c_str() );    #endif}Obviously, typing that much code gets pretty tedious ... but wrapping it up in an inline function and/or macro is easy enough. My engine is absolutely covered in single-line debug outputs, scalable with a debug level (0,1,2,3). If things are working fine I get basic debug output, but as soon as it explodes I up it to #3 and I can pretty much see every choice the program has made [grin]Jack   ;  The file format is correct. But i don't understand why my program don't find the mesh file.. That's all in the same directory.   ;Quote:Original post by TanoThe file format is correct. But i don't understand why my program don't find the mesh file.. That's all in the same directory.I think you need to check your assumptions. As indicated by two of the previous replies, VStudio can change the current working directory - meaning that you're not "looking" in the place you think you are.Have a look into GetCurrentDirectory():WCHAR wcActualPath[ MAX_PATH ];if( SUCCEEDED( GetCurrentDirectory( MAX_PATH, wcActualPath ) ) ){    OutputDebugString( wcActualPath );}hthJack   ;  I don't be able to use visual studio very well. But i tried in this mode:mesh1 = dxMgr->loadMesh("C:/Tano_DirectX_Project/Videologie/Debug/mappa.x");But without result..   ;  That's all program:#include <windows.h>#include <mmsystem.h>#include <d3d9.h>#include <d3dx9tex.h>#include <dinput.h>#include <string>/*******************************************************************************/* Class dxManager /* Note: Dichiarazione della classe, componenti basi.*******************************************************************************/class dxManager{public:dxManager(void);~dxManager(void);voiddrawMesh(LPD3DXMESH pMesh, D3DXVECTOR3 position);IDirect3DSurface9*  getSurfaceFromBitmap(std::string filename, int width, int height);IDirect3DSurface9*  getBackBuffer(void);voidblitToSurface(IDirect3DSurface9* srcSurface, const RECT *srcRect, const RECT *destRect);LPD3DXMESH loadMesh(std::string filename);void createCamera(float nearClip, float farClip);void moveCamera(D3DXVECTOR3 vec);void pointCamera(D3DXVECTOR3 vec);private:HRESULT  lastResult;LPDIRECT3D9   pD3D;LPDIRECT3DDEVICE9  pd3dDevice;D3DMATERIAL9*m_pMeshMaterials;DWORDm_dwNumMaterials;// Number of materials// screen detailsint screen_width;int screen_height;// camera detailsD3DXMATRIX matView;D3DXMATRIX matProj;D3DXVECTOR3 position;D3DXVECTOR3 lookPos;};/*******************************************************************************/* Metodi .*******************************************************************************/dxManager::dxManager(void){pD3D = NULL; pd3dDevice = NULL;screen_width = 640;screen_height = 480;}dxManager::~dxManager(void){}/*******************************************************************************/* DRAWMESH() /* Note: *******************************************************************************/void dxManager::drawMesh(LPD3DXMESH pMesh, D3DXVECTOR3 position){    D3DXMATRIX matPos;D3DXMATRIX meshMatrix, scaleMatrix, rotateMatrix;D3DXMatrixTranslation(&matPos, position.x, position.y, position.z);createCamera(1.0f, 750.0f);// near clip plane, far clip planemoveCamera(D3DXVECTOR3(0.0f, 0.0f, -450.0f));pointCamera(D3DXVECTOR3(0.0f, 0.0f, 0.0f));// set the rotationD3DXMatrixRotationY(&rotateMatrix, timeGetTime()/1000.0f);// set the scalingD3DXMatrixScaling(&scaleMatrix, 0.5f, 0.5f, 0.5f);// multiple the scaling and rotation matrices to create the meshMatrixD3DXMatrixMultiply(&meshMatrix, &scaleMatrix, &rotateMatrix);// multiple the scaling and rotation matrices to create the meshMatrixD3DXMatrixMultiply(&meshMatrix, &matPos, &meshMatrix);// transform the object in world spacepd3dDevice->SetTransform(D3DTS_WORLD, &meshMatrix);for(DWORD i = 0; i < m_dwNumMaterials; i++){pd3dDevice->SetMaterial(&m_pMeshMaterials);    pMesh->DrawSubset(i);}}/*******************************************************************************/* LOADMESH() /* Note: *******************************************************************************/LPD3DXMESH dxManager::loadMesh(std::string filename){HRESULT hr;LPD3DXMESH tempMesh;LPD3DXBUFFER ppAdjacencyBuffer;LPD3DXBUFFER pD3DXMtrlBuffer = NULL;tempMesh = NULL;    // Load the mesh from the specified file    hr = D3DXLoadMeshFromX( filename.c_str(), D3DXMESH_SYSTEMMEM, pd3dDevice,    &ppAdjacencyBuffer, &pD3DXMtrlBuffer, NULL,   &m_dwNumMaterials, &tempMesh );    if( FAILED(hr) )return NULL;D3DXMATERIAL* matMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();   //Create two arrays. One to hold the materials and only to hold the textures    m_pMeshMaterials = new D3DMATERIAL9[m_dwNumMaterials];   for(DWORD i = 0; i < m_dwNumMaterials; i++)    {   //Copy the material   m_pMeshMaterials = matMaterials.MatD3D;   //Set the ambient color for the material (D3DX does not do this)   m_pMeshMaterials.Ambient = m_pMeshMaterials.Diffuse;    }return tempMesh;}/*******************************************************************************/* CAMERA /* Note: Inizializzazioni e funzioni per la gestione della camera.*******************************************************************************/void dxManager::createCamera(float nearClip, float farClip){//Here we specify the field of view, aspect ration and near and far clipping planes.    D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, screen_width/screen_height, nearClip, farClip);    pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);}void dxManager::moveCamera(D3DXVECTOR3 vec){position = vec;}void dxManager::pointCamera(D3DXVECTOR3 vec){lookPos = vec;D3DXMatrixLookAtLH(&matView, &position,//Camera Position   &lookPos,//Look At Position   &D3DXVECTOR3(0.0f, 1.0f, 0.0f));//Up Directionpd3dDevice->SetTransform(D3DTS_VIEW, &matView);}/*******************************************************************************/* M A I N *******************************************************************************/HINSTANCE hInst;// holds the instance for this appHWND wndHandle;// global window handle//Variabili per Modelli LPD3DXMESH mesh1;//Variabili varie// Our custom FVF, which describes our custom vertex structure#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)LPDIRECT3D9   pD3D;LPDIRECT3DDEVICE9  pd3dDevice;////////////////////////////////////////////// forward declarationsbool    initWindow(HINSTANCE hInstance);LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);// direct3D functionsbool initDirect3D(HWND hwnd);void shutdown(void);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){// call our function to init and create our windowif (!initWindow(hInstance)){MessageBox(NULL, "Unable to create window", "ERROR", MB_OK);return false;}dxManager *dxMgr = new dxManager();// init direct3dinitDirect3D(wndHandle);mesh1 = dxMgr->loadMesh("C:/Tano_DirectX_Project/Videologie/Debug/mappa.x");if (!mesh1){MessageBox(wndHandle, "can't load xfile", "ERROR", MB_OK);return false;}// Main message loop:// Enter the message loop    MSG msg;ZeroMemory( &msg, sizeof(msg) );    while( msg.message!=WM_QUIT )    {// check for messagesif( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )   {TranslateMessage( &msg );  DispatchMessage( &msg );   }// this is called when no messages are pendingelse{// call our render functionpd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );pd3dDevice->BeginScene();dxMgr->drawMesh(mesh1, D3DXVECTOR3(100.0f, -100.0f, 0.0f));pd3dDevice->EndScene();pd3dDevice->Present( NULL, NULL, NULL, NULL );}    }// shutdown the directx managershutdown();return (int) msg.wParam;}bool initDirect3D(HWND hwnd){HRESULT hr;if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ){return false;}D3DPRESENT_PARAMETERS d3dpp;ZeroMemory( &d3dpp, sizeof(d3dpp) );    d3dpp.Windowed = TRUE;    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;d3dpp.BackBufferCount  = 1;d3dpp.BackBufferHeight = 480;d3dpp.BackBufferWidth  = 640;d3dpp.hDeviceWindow    = hwnd;    hr = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,    D3DCREATE_SOFTWARE_VERTEXPROCESSING,    &d3dpp, &pd3dDevice );if FAILED (hr)    {   return false;    }return true;}void shutdown(void){    if( pd3dDevice != NULL) {   pd3dDevice->Release();pd3dDevice = NULL;}    if( pD3D != NULL){   pD3D->Release();pD3D = NULL;}}bool initWindow(HINSTANCE hInstance){WNDCLASSEX wcex;wcex.cbSize = sizeof(WNDCLASSEX);wcex.style= CS_HREDRAW | CS_VREDRAW;wcex.lpfnWndProc= (WNDPROC)WndProc;wcex.cbClsExtra= 0;wcex.cbWndExtra= 0;wcex.hInstance= hInstance;wcex.hIcon= 0;wcex.hCursor= LoadCursor(NULL, IDC_ARROW);wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);wcex.lpszMenuName= NULL;wcex.lpszClassName= "DirectXExample";wcex.hIconSm= 0;RegisterClassEx(&wcex);wndHandle = CreateWindow("DirectXExample",  "DirectXExample",  WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,  CW_USEDEFAULT,  640,  480,  NULL,  NULL,  hInstance,  NULL);   if (!wndHandle) return false; ShowWindow(wndHandle, SW_SHOW);   UpdateWindow(wndHandle);   return true;}LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){switch (message) {case WM_DESTROY:PostQuitMessage(0);break;}return DefWindowProc(hWnd, message, wParam, lParam);};  Hmm, usually the error is in the file path/location. The next obvious step is to work out what the HRESULT is and see if the debug runtimes spit out anything useful.See the link in my signiture for information on DirectX Debugging if you're not familiar with it. Usually the debug runtimes will give a more descriptive explanation/message as to what it doesn't like [smile]hthJack   ;  [edit] Ignore the following. [/edit]And of course there's the fact that that is not a path in Windows. Change:"C:/Tano_DirectX_Project/Videologie/Debug/mappa.x"to"C:\\Tano_DirectX_Project\\Videologie\\Debug\\mappa.x"jfl.[Edited by - jflanglois on December 2, 2005 4:57:22 PM]