CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

Using Visual studio 2008 and error C2664 C2440 topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-29-2008, 10:26 PM
Junior Member
 
Join Date: Sep 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
soong is on a distinguished road
| More
Using Visual studio 2008 and error C2664 C2440

Hi,

I've been doing basic programming with Java, and have recently started to familiarize with c++ so forgive me if this is a really noob question

I'm using Microsoft Visual Studio 2008 and looking at code examples from the internet

when I try to compile some code I usually get the errors


for the line
ofn.lpstrFilter = "Text Files (*.txt)\0*.ufc\0All Files (*.*)\0*.*\0";
error C2440: '=' : cannot convert from 'const char [56]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

which i can use the TEXT casting thing to overcome
and


for the line

HWND hwnd = CreateWindow(sClassName,(LPCWSTR)TEXT(sAppName),WS _OVERLAPPED | WS_MINIMIZEBOX |WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_DLGFRAME | WS_BORDER, CW_USEDEFAULT,CW_USEDEFAULT,275,137,0,0,hinst,0);
error C2440: '=' : cannot convert from 'const char [56]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

which i have not been able to solve yet.

I was wondering why do I have to edit code which should already be working? I thought perhaps its to with using C code and adding it to a C++ project, but these examples were taken from C++ programs.

Thx
soong
Reply With Quote
  #2  
Old 09-30-2008, 08:25 AM
Senior Member
 
Join Date: Jul 2008
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
xpi0t0s is on a distinguished road
| More
Re: Using Visual studio 2008 and error C2664 C2440

There's a lot of casting involved in Windows programming, due to the generic nature of the interfaces. As long as you're certain the data pointed to is correct, there's nothing wrong with a cast. There's a lot less casting nowadays than there used to be, but casting from different string types to each other is still unfortunately quite common.

Don't double cast though, as in (LPCWSTR)TEXT(szAppName). You should only ever need one cast.

You don't say where the code comes from, but my guess is that it's either from older Windows programs where the rules aren't as strict or they're from non-Windows programs.
Reply With Quote
  #3  
Old 10-04-2008, 01:29 AM
Junior Member
 
Join Date: Sep 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
soong is on a distinguished road
| More
Re: Using Visual studio 2008 and error C2664 C2440

thx for reply, and sorry for my late reply

and yeah i'm assuming that the code is pretty old.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
techfest 2008 and microsoft present knockout!! harishreddy.iit Contests 2 04-28-2009 07:47 PM
Refactoring in VC++/Visual Studio AB MFC Programming 2 06-27-2008 06:01 AM
I have Win XP SP1 but I need Visual C++ 2005 CODINGMASTER C++ Programming 4 08-20-2007 10:47 AM
Visual Studio hangs during Debugging a thread: PfisterHarald MFC Programming 0 09-13-2006 12:30 PM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 04:40 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board