Public Group

# Problem with const char to LPCWSTR conversion

This topic is 3413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

ok so im currently working on a game and i've been getting some strange outputs i wont copy in all my source code because there is alot and everything is set correctly.... well that i know of. error C2664: 'TextOutW' : cannot convert parameter 4 from 'const char *' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast error C2664: 'CreateWindowExW' : cannot convert parameter 3 from 'const char *' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
// this is where the compiler is taking me to for the first error message..
void
CLevel::DrawScore()
{
HDC hdc = CGame::GetInstance().GetBackBuffer()->GetBFDC();

const int kiX = 0;
const int kiY = m_iHeight - 50;

TextOut(hdc, kiX, kiY, m_strScore.c_str(), static_cast<int>(m_strScore.size()));
}

// and this is the second error message, i believe its referring to the const char* _pcTitle..

HWND
CreateAndRegisterWindow(HINSTANCE _hInstance, int _iWidth, int _iHeight, const char* _pcTitle)
{
WNDCLASSEX winclass;

winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = _hInstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));

winclass.lpszClassName = WINDOW_CLASS_NAME;
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&winclass))
{
//failed to register
return(0);
}
HWND hwnd;
hwnd = CreateWindowEx(NULL,
WINDOW_CLASS_NAME,
_pcTitle,
WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
_iWidth, _iHeight,
NULL,
NULL,
_hInstance,
NULL);


i've had a look around the net and cant seem to find anything that a solution to my problem and any help would be great! :D:D:D

##### Share on other sites
LPCWSTR = Long Pointer Const Wide STRing, or in otherwords, a const wchar_t*.

So the error reads: cannot convert from 'const char *' to 'const wchar_t *'

This error is caused when windows thinks you're compiling with Unicode support.

To fix, go to your project properties (alt+f7), and change "Character Set" from "Unicode" to "Not Set".

EDIT:
C-style => const

[Edited by - _fastcall on May 18, 2009 10:22:20 PM]

##### Share on other sites
out of interest, is there any other ways to fix it with unicode being set?

just because i've been taught to use unicode. but obviously this does work the game is working at the moment and thanks for the tip... seems simple in retrospect a positive of peer review i spose...

but yeah, any other fixes with unicode still being set?

##### Share on other sites
Yes, use std::wstring instead of std::string, L"Text" instead of "Text", and wchar_t instead of char.

##### Share on other sites
Quote:
 Original post by _fastcallLPCWSTR = Long Pointer C-style Wide STRing, or in otherwords, a wchar_t*.
Just FYI, the "C" stands for "const" not "C-style". So LPCWSTR corresponds to wchar_t const * while LPWSTR is the non-const, wchar_t * version.

That doesn't change anything else that was said, though...

##### Share on other sites
ok thanks fastcall...:D:D:D

umm another problem... sorry

1>clock.obj : error LNK2019: unresolved external symbol __imp__timeGetTime@0 referenced in function "public: virtual void __thiscall CClock::Process(void)" (?Process@CClock@@UAEXXZ)
fatal error LNK1120: 1 unresolved externals

voidCClock::Process(){	m_fLastTime = m_fCurrentTime;	m_fCurrentTime = static_cast<float>(timeGetTime());	if (m_fLastTime == 0.0f)	{		m_fLastTime = m_fCurrentTime;	}	m_fDeltaTime = m_fCurrentTime - m_fLastTime;	m_fTimeElapsed += m_fDeltaTime;}

obviously my clock object is having trouble with the linker?... and its something to do with timeGetTime() but what i dont get is my clock.cpp/.h are part of my re-useable code so i just copy and paste it and it's worked in other app's i've used it in.. so i dont get the problem

##### Share on other sites
Quote:
 Original post by CodekaJust FYI, the "C" stands for "const" not "C-style".

Ah, that's right; edit'd post.

Quote:
 Original post by TroyM881>clock.obj : error LNK2019: unresolved external symbol __imp__timeGetTime@0 referenced in function "public: virtual void __thiscall CClock::Process(void)" (?Process@CClock@@UAEXXZ)fatal error LNK1120: 1 unresolved externalsobviously my clock object is having trouble with the linker?... and its something to do with timeGetTime() but what i dont get is my clock.cpp/.h are part of my re-useable code so i just copy and paste it and it's worked in other app's i've used it in.. so i dont get the problem

What's happening is that your source file, CClock.cpp (I'm assuming), is troubling the linker; the file is saying "Here's all the definitions for the CClock methods as declared in CClock.h; oh, and I'm also using timeGetTime() as I see it declared -- but not defined -- in <windows.h>, I'll rely on the linker to supply the definition to me later." Then the linker is saying, "Awesome, CClock.obj, has a the definitions for CClock! It also looks like it's needing a definition of timeGetTime(), but I don't have a definition for it!"

You'll need to link winmm.lib to your project for the timeGetTime function. Go to your project settings, select "input" under "linker", and append winmm.lib in the "Additional libraries" field.

Also, for future reference, you can usually Google the terms "msdn [function name]" and the documents usually state which microsoft libraries to link with which functions.

[Edited by - _fastcall on May 18, 2009 11:51:45 PM]

##### Share on other sites
ahhhhhhhhhhhhhhh.... that does make sense i'd have to include the .lib that deltatick uses...

thanks fastcall..

1. 1
2. 2
Rutin
20
3. 3
4. 4
frob
15
5. 5

• 10
• 9
• 14
• 9
• 33
• ### Forum Statistics

• Total Topics
632592
• Total Posts
3007295

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!