|
-
Nov 9th, 2002, 03:46 AM
#1
Thread Starter
Lively Member
Strings and the Win API
Alright, I can send strings to api functions using the .c_str() deal, but that only works for functions like MessageBox that don't change it. How can I send strings so that these functions can modify them. An example of RegEnumKey would be great
-
Nov 9th, 2002, 06:07 AM
#2
Monday Morning Lunatic
You can't. You need to allocate a buffer using new[] of the correct size (all Win32 API functions that return a string into a buffer also provide "safe" ways to get the length of said string) then construct a string from that buffer, and delete[] the buffer.
The Win32 API doesn't understand C++ strings.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 9th, 2002, 06:35 AM
#3
Thread Starter
Lively Member
I've been using LPSTRs, HeapAlloc(), and HeapFree(). Is that the "right" way to do it, or just a way to do it?
-
Nov 9th, 2002, 07:12 AM
#4
You could also use new[] and delete[], but there actually is no difference.
Unless I start talking about UNICODE
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 9th, 2002, 07:55 AM
#5
Monday Morning Lunatic
When it comes down to it, new[] and delete[] will indirectly call HeapAlloc(), although it's not guaranteed (they may allocate an arena from the OS, then manage that internally, extending it where necessary).
So yeah, your method is as good as any, since LPSTR is just a typedef for char*. Only thing that could make it a "wrong" way is that it's unportable, but if you're making a program for Windows that's a given
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 9th, 2002, 08:40 AM
#6
Thread Starter
Lively Member
Why is it different in UNICODE?
-
Nov 9th, 2002, 09:18 AM
#7
Quite a few little differences. Like, you can't use string the way it is, LPSTR, or any allocation functions except new without changes.
I'm sure there's a lot of material to be found on the web.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|