Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC
dear friends
 

in this function use the written code
 

 
char * pchData;
pchData = (char*)GlobalLock(hClipboardData);
 
strcpy(pchData, LPCSTR(strData));
 

 
this code run to error
error C2440: '' : cannot convert from 'CString' to 'LPCSTR'
 

solve the problem
plz.........
Posted 28-Jun-13 11:15am
Comments
nv3 at 28-Jun-13 16:52pm
   
You would be better off to use the green Improve question button instead of reposting the same question within a half hour's time. That would keep your helpers focused on what your are trying to do.
H.Brydon at 28-Jun-13 16:55pm
   
Agreed, just noticed that myself. I would have answered differently if I had known...

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Since CString is supposedly a container for constant strings, my guess is that your C++ project is Unicode and by attempting to cast CString to LPCSTR, you are also trying to convert wide string to ANSI.
 
(Without trying it myself first) try each of the following.
 
(1) drop the cast:
strcpy(pchData, strData);
This will let the compiler decide what to do with strData instead of using your forced cast.
(2) if that doesn't work, change your project from Unicode to ANSI.
(3) if you can't do that, convert the wide character string to ANSI or else use the wide characters in the clipboard data. This is a little more complicated than can be easily shown here but is straightforward. Google will help you.
 
These items assume that strData is a CString (which you haven't properly shown).
 
Also, you should really get in the habit of using strcpy_s() instead of strcpy(). This is more modern and will help you fix dozens of bugs in your code.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 381
1 Praneet Nadkar 237
2 Marcin Kozub 225
3 Sergey Alexandrovich Kryukov 195
4 Shweta N Mishra 161
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 28 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100