Click here to Skip to main content
11,716,938 members (78,819 online)
Rate this: bad
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
Posted 28-Jun-13 10:15am
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
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.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 449
1 OriginalGriff 265
2 F-ES Sitecore 210
3 Maciej Los 135
4 Jochen Arndt 120
0 Sergey Alexandrovich Kryukov 1,144
1 Maciej Los 509
2 OriginalGriff 505
3 Richard MacCutchan 440
4 CHill60 415

Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 28 Jun 2013
Copyright © CodeProject, 1999-2015
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