Re: Problem with using char* to return string by reference
swtbase@gmail.com wrote:
Although you suggested that UTF and UNICODE formats could be a problem
for char*, I want to restate that I have already used cout to print
temp and a (local to ReadInitRegValue()) values from within the
ReadInitRegValue() func and they return correctly, 'Intel LAN
Adapter'.
So, if I understand correctly, you have a value that gets displayed
correctly inside a function but not outside?
What my real problem is returning char* a (local to
ReadInitRegValue()) by reference back to main(). I wrote a small class
having a char[] array inside it and used object from it to return by
reference. In this case, the value was correctly returned to main().
I can't guess what your code looks like. In any case, it would help if you
reduced your code to the smallest possible example. If you could e.g.
eliminate the registry access from your original code, then everybode even
without that certain key at that position could reproduce the problem.
Also, remove the unnecessary calls, i.e. those that only retrieve some
values that are converted to floats. That would also make sure that reading
and interpreting the registry is not the cause of the error.
I use the ancient VC++ 6 complier. I don't have cstring.h and don't
want to use vector stuff. What options do I have?
Ahem, for what? If you are looking for std::string, that class is defined in
<string> (no '.h'!).
And no, staying away from Win32 API is a bad advice for me. I just
can't give up something complicated.
Well, I'd say you are trying to handle too much for now. Get a bit more
acquainted to C++ first, then it will be much easier to tackle the win32
interface.
Again, staying away from cast is impossible in this case (I personally
don't like casting). Even MSDN example uses cast of LPBYTE (unsigned
char*). I don't think casting from char* to unsigned char* is very
much dangerous. Both type of char use the same amount of memory but
only differ in value range. What do you think?
I think the MSDN examples are not always the best imaginable code. Anyway, I
guess that in this case you actually can't help casting, but be aware of
the dangers and avoid casting in general. Using the correct type is much
better, because it works reliably.
good luck
Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite
Sator Laser GmbH
Gesch??ftsf??hrer: Thorsten F??cking, Amtsgericht Hamburg HR B62 932