Jump to content

  • Log In with Google      Sign In   
  • Create Account

[C++]cstring to lpstr


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 HawkAgent   Members   -  Reputation: 122

Like
0Likes
Like

Posted 29 June 2007 - 11:57 PM

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

Sponsor:

#2 Spoonbender   Members   -  Reputation: 1254

Like
0Likes
Like

Posted 30 June 2007 - 12:17 AM

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]

#3 HawkAgent   Members   -  Reputation: 122

Like
0Likes
Like

Posted 30 June 2007 - 10:07 AM

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());

[/code]
doesn't work: error C2440: 'initializing' : cannot convert from 'wchar_t *' to 'LPSTR'

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

#4 nef   Members   -  Reputation: 129

Like
0Likes
Like

Posted 30 June 2007 - 11:10 AM

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.



#5 HawkAgent   Members   -  Reputation: 122

Like
0Likes
Like

Posted 01 July 2007 - 01:06 AM

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();



#6 nobodynews   Crossbones+   -  Reputation: 1913

Like
0Likes
Like

Posted 01 July 2007 - 03:09 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS