Click here to Skip to main content
13,055,047 members (60,602 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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: '<function-style-cast>' : cannot convert from 'CString' to 'LPCSTR'

solve the problem
Posted 28-Jun-13 10:15am
nv3 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 28 Jun 2013
Copyright © CodeProject, 1999-2017
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