Sign in to follow this  
johnnyBravo

Whats wrong with this LPCTSTR name = "Runner"? possible visual c++ 2005b2 problem?

Recommended Posts

hi in my c++ program ive got: #define WIN32_MEAN_AND_LEAN #include <windows.h> #define CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h> #include <string> #include <sstream> #include <vector> #include <fstream> #include <iostream> #include <iomanip> LPCTSTR name = "Runner"; and im getting the error:
Quote:
error C2440: 'initializing' : cannot convert from 'const char [7]' to 'LPCTSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
i can't work out why its doing this. Im using the visual c++ 2005 beta 2 edition, under 'console application' because for some reason i can't select win32 app in the project creation window, which might be causing this problem? thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by johnnyBravo
i can't work out why its doing this. Im using the visual c++ 2005 beta 2 edition, under 'console application' because for some reason i can't select win32 app in the project creation window, which might be causing this problem?


Take a look at my post here and a few above to see why. If you are not using the express edition, you should be able to make a Win32 app - you make a console app project, but then choose the 'Application Settings' option on that final screen before the project is made and choose Win32. Given that, you should have the platform SDK downloaded and installed as well.

As for the code, I think you have to do something like:
LPCTSTR name = _T("Runner"); or something like that to assign a literal to a pointer. This is probabally because either LPCSTR was redefined in the new SDK, or something like that. Also try a LPCTSTR name = reinterpret_cast<LPCTSTR>("Runner") as well. Good luck!

[edit]Or what AP said [smile]

Share this post


Link to post
Share on other sites
_T("Runner"); didnt work, while the others did, the caption for my window looks like a solid white rectangle tho.

Ok I fixed the win32 app thanks to your post, but its kinda weird. In projects I made from beta 1, they work fine, eg i can just use:
wc.lpszClassName = "Runner";
or:
HWND hwnd = CreateWindow(wc.lpszClassName, "The caption",...


and these work fine.

its when I try the same thing in beta 2 created project, i ge the error i posted above. any ideas on what happening here?

Thanks

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