"const char *" is incompatible with parameter of type "LPCWSTR" error
Posted
by
N0xus
on Game Development
See other posts from Game Development
or by N0xus
Published on 2012-07-04T15:04:06Z
Indexed on
2012/07/04
15:24 UTC
Read the original article
Hit count: 1042
I'm trying to incorporate some code from Programming an RTS Game With Direct3D into my game. Before anyone says it, I know the book is kinda old, but it's the particle effects system he creates that I'm trying to use.
With his shader class, he intialise it thusly:
void SHADER::Init(IDirect3DDevice9 *Dev, const char fName[], int typ)
{
m_pDevice = Dev;
m_type = typ;
if(m_pDevice == NULL)return;
// Assemble and set the pixel or vertex shader
HRESULT hRes;
LPD3DXBUFFER Code = NULL;
LPD3DXBUFFER ErrorMsgs = NULL;
if(m_type == PIXEL_SHADER)
hRes = D3DXCompileShaderFromFile(fName, NULL, NULL, "Main", "ps_2_0", D3DXSHADER_DEBUG, &Code, &ErrorMsgs, &m_pConstantTable);
else hRes = D3DXCompileShaderFromFile(fName, NULL, NULL, "Main", "vs_2_0", D3DXSHADER_DEBUG, &Code, &ErrorMsgs, &m_pConstantTable);
}
How ever, this generates the following error:
Error 1 error C2664: 'D3DXCompileShaderFromFileW' : cannot convert parameter 1 from 'const char []' to 'LPCWSTR'
The compiler states the issue is with fName in the D3DXCompileShaderFromFile line.
I know this has something to do with the character set, and my program was already running with a Unicode Character set on the go. I read that to solve the above problem, I need to switch to a multi-byte character set. But, if I do that, I get other errors in my code, like so:
Error 2 error C2664: 'D3DXCreateEffectFromFileA' : cannot convert parameter 2 from 'const wchar_t *' to 'LPCSTR'
With it being accredited to the following line of code:
if(FAILED(D3DXCreateEffectFromFile(m_pD3DDevice9,effectFileName.c_str(),NULL,NULL,0,NULL,&m_pCurrentEffect,&pErrorBuffer)))
This if is nested within another if statement checking my effectmap list. Though it is the FAILED word with the red line. Like wise I get the another error with the following line of code:
wstring effectFileName = TEXT("Sky.fx");
With the error message being:
Error 1 error C2440: 'initializing' : cannot convert from 'const char [7]' to 'std::basic_string<_Elem,_Traits,_Ax>'
If I change it back to a Uni code character set, I get the original (fewer) errors. Leaving as a multi-byte, I get more errors.
Does anyone know of a way I can fix this issue?
© Game Development or respective owner