• Advertisement
Sign in to follow this  

[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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Hi, thanks for the reply.

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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement