Jump to content
  • Advertisement
Sign in to follow this  
TroyM88

Problem with const char to LPCWSTR conversion

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

If you intended to correct an error in the post then please contact us.

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.lpszMenuName = NULL;
	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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by _fastcall
LPCWSTR = 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 this post


Link to post
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


void
CClock::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 this post


Link to post
Share on other sites
Quote:
Original post by Codeka
Just FYI, the "C" stands for "const" not "C-style".


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

Quote:
Original post by TroyM88
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

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


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 this post


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

thanks fastcall..

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!