# [C++]cstring to lpstr

This topic is 3858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I want to copy a CString to the Clipboard, apparently I need to convert the CString to LPSTR. How do I do this?

##### Share on other sites
After roughly 8 seconds on Google:
Using CString
How to convert from CString to LPSTR?

Impressive how these must have been posted within the last minutes, since you couldn't find them when you tried to find an answer, because of course you tried a simple [google] search before posting here. [wink]

##### Share on other sites
Ofcourse I search before I post... I tried google, searched for like 30min
the method in the 2nd link:
[code
LPSTR OriginChar= theCString.GetBuffer(theCString.GetLength());

doesn't work: error C2440: 'initializing' : cannot convert from 'wchar_t *' to 'LPSTR'

And the first link... can't find any usefull information...

##### Share on other sites
umm, if your using wchar_t's try setting this option in visual studio:

right click on your project and go to the project properties, then in the general section you should see a box for character set, change that to not set.

It will make your program not use wide characters, so you cant have your app in japanses or other funky languages, but it should work.

Alternativly, you need to find the wide character version of the function that needs a LPSTR.

BTW, LPSTR is just fancy for (char *). LPWSTR is what you have with your wchar_t's.

Hope that helps.

##### Share on other sites

I tried what you suggested. The error doesn't come up, but there is another error:

1>mt.exe : general error c101008a: Failed to save the updated manifest to the file ".\Debug\statmodv1.exe.embed.manifest". The parameter is incorrect.

Maybe there is something wrong with my code...
LPSTR lpCmdLine = temp.GetBuffer(0); //temp is the string that I want to copy to clipboard	  HGLOBAL      temp_Handle ;      char*         temp_ptr ;  OpenClipboard();         temp_Handle =  GlobalAlloc (GMEM_MOVEABLE + GMEM_DDESHARE,                                  strlen(lpCmdLine) + 1 );  temp_ptr = (char*)GlobalLock(temp_Handle);  memcpy (temp_ptr, lpCmdLine, strlen(lpCmdLine)+1);  GlobalUnlock(temp_Handle);  EmptyClipboard();  SetClipboardData(CF_TEXT, temp_Handle);  CloseClipboard();

##### Share on other sites
I googled that error code and found this link. I think the solution was to just clean your solution (Build->Clean Solution). Hope that helps.