Sign in to follow this  
cannyshammy

cannot convert from 'LPSTR' to 'LPCWSTR'

Recommended Posts

Im getting this, and other simmilar errors: error C2664: 'D3DXCreateTextureFromFileW' : cannot convert parameter 2 from 'LPSTR' to 'LPCWSTR' error C2664: 'D3DXLoadMeshFromXW' : cannot convert parameter 1 from 'const char [10]' to 'LPCWSTR' error C2664: 'lstrcpynW' : cannot convert parameter 2 from 'LPSTR' to 'LPCWSTR' error C2664: 'lstrlenW' : cannot convert parameter 1 from 'LPSTR' to 'LPCWSTR' error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [27]' to 'LPCWSTR' On a mesh loading function:

HRESULT CMyMesh::LoadMeshData( IDirect3DDevice9 *pd3dDevice)
{
    LPD3DXBUFFER pD3DXMtrlBuffer;

    // Load the mesh from the specified file
    if( FAILED( D3DXLoadMeshFromX( "captain.x", D3DXMESH_SYSTEMMEM, 
                                   pd3dDevice, NULL, 
                                   &pD3DXMtrlBuffer, NULL, &m_dwNumMaterials, 
                                   &m_pMesh ) ) )
    {
       
        //MessageBox(NULL, "Could not find the mesh", "Meshes.exe", MB_OK);
        return FALSE;

    }

	// Extracting infomation used later to mod the mesh
	m_dwNumVertices	= m_pMesh->GetNumVertices();
	m_dwDataSize	= m_pMesh->GetNumBytesPerVertex();
	m_dwFVF			= m_pMesh->GetFVF();

    // We need to extract the material properties and texture names from the 
    // pD3DXMtrlBuffer
    D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
    m_pMeshMaterials = new D3DMATERIAL9[m_dwNumMaterials];
    m_pMeshTextures  = new LPDIRECT3DTEXTURE9[m_dwNumMaterials];

    for( DWORD i=0; i<m_dwNumMaterials; i++ )
    {
        // Copy the material
        m_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;

        // Set the ambient color for the material (D3DX does not do this)
        m_pMeshMaterials[i].Ambient = m_pMeshMaterials[i].Diffuse;

        m_pMeshTextures[i] = NULL;
        if( d3dxMaterials[i].pTextureFilename != NULL && 
            lstrlen(d3dxMaterials[i].pTextureFilename) > 0 )
        {
            // Create the texture
            if( FAILED( D3DXCreateTextureFromFile( pd3dDevice, 
                                                d3dxMaterials[i].pTextureFilename, 
                                                &m_pMeshTextures[i] ) ) )
            {
                // If texture is not in current folder, try parent folder
                const TCHAR* strPrefix = TEXT("..\\");
                const int lenPrefix = lstrlen( strPrefix );
                TCHAR strTexture[MAX_PATH];
                lstrcpyn( strTexture, strPrefix, MAX_PATH );
                lstrcpyn( strTexture + lenPrefix, d3dxMaterials[i].pTextureFilename, MAX_PATH - lenPrefix );
                // If texture is not in current folder, try parent folder
                if( FAILED( D3DXCreateTextureFromFile( pd3dDevice, 
                                                    strTexture, 
                                                    &m_pMeshTextures[i] ) ) )
                {
                    MessageBox(NULL, "Could not find texture map", "Meshes.exe", MB_OK);
                }
            }
        }
    }

    // Done with the material buffer
    pD3DXMtrlBuffer->Release();
}


Its going to be part of my project for university that i outline here: http://www.gamedev.net/community/forums/topic.asp?topic_id=279521 The wierd thing i used this code in another file just to make sure i could load a mesh file and it worked fine. But since i have tried to move the code into its own class so i can use it in conjunction with a GUI (the one from the summer SDK) it has decided to throw up these conversion errors. Sorry if this seems abit nooby, but i have only been doing c++ 6weeks now *chuckle*... Thanks, Mike

Share this post


Link to post
Share on other sites
You probably want to be using the UNICODE version of the string functions, so instead of lstrcpyn use lstrcpynW, ect...

Oh, and I just noticed that when you're compiling you're linking against the UNICODE versions of the functions, if you don't care if you're UNICODE or not, then see if you have "_UNICODE" defined and turn it off.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
or better yet _T("text") or TEXT("text")


Yup, mutch better for the general case, although I assumed the OP was using the new 9.0c SDK sample framework which uses WCHAR and L"this is a string" type syntax.

Probably best to use your approach (macros) incase MS change their mind later (on UNICODE) :)

Cambo_frog

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this