cannot convert from 'LPSTR' to 'LPCWSTR'

Started by
4 comments, last by cannyshammy 19 years, 5 months ago
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 = d3dxMaterials.MatD3D;

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

        m_pMeshTextures = NULL;
        if( d3dxMaterials.pTextureFilename != NULL && 
            lstrlen(d3dxMaterials.pTextureFilename) > 0 )
        {
            // Create the texture
            if( FAILED( D3DXCreateTextureFromFile( pd3dDevice, 
                                                d3dxMaterials.pTextureFilename, 
                                                &m_pMeshTextures ) ) )
            {
                // 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.pTextureFilename, MAX_PATH - lenPrefix );
                // If texture is not in current folder, try parent folder
                if( FAILED( D3DXCreateTextureFromFile( pd3dDevice, 
                                                    strTexture, 
                                                    &m_pMeshTextures ) ) )
                {
                    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
Advertisement
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.
Also, instead of specifying your string literals as:
"captain.x"

use:

L"captain.x"

(note the L prefix)

HTH,
Cambo_frog
For the love of god, please tell me that you've just omitted your error checking code for brevity, and you don't really assume that all those functions succeed.
or better yet _T("text") or TEXT("text")
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
For the love of god, please tell me that you've just omitted your error checking code for brevity, and you don't really assume that all those functions succeed.
Thankyou very much both of you two, very usefull posts :) Now just to go away and find out what UNICODE means heheheh :)

Mike

This topic is closed to new replies.

Advertisement