Log in

No account? Create an account
20 May 2005 @ 07:08 am
I am weak  
Does anyone know a _good_ way to convert a BYTE* to a CComBSTR and back again?

I can do it by memcpying to a char* first and converting _that_ to a CComBSTR, but that's kinda dumb.

In other news, i just bought a lot of books :)

I've been waiting for a long time for James Alan Gardner's "Radiant" and S.M. Stirling's "Dies the Fire" to come out, and complained about the wait rrepeatedly in the meantime :)

So yesterday i got an email from SFBC saying they were doing a 24 hour 2 for 1 sale. I immediatly thought of those two books and SFBC followed it up by listing some of their new books, including the newest book in Mercedes Lackey's dragon-jousting series (the one that starts out as a Jane Yolen look-alike,) and Laurel K. Hamilton's "A Stroke of Midnight"

I wasn't able to resist the combined temptation, so i logged on last night and got those four and while doing so saw that they had an omnibus of the two latest books in Charlaine Harriis' Southern Vampire Mysteries series. So after adding that i needed to add a sixth book so i could get it for free. I eventually decided on an omnibus of Anne McCaffrey's Harper Hall trillogy since i was being annoyed a few months ago about not having them.

With shipping it came out to $52. About $8.50 per physical book and $5.75 per published book. So around the same price i would have paid for paperbacks at Borders, but without the wait. However it was still kind of silly, because i may feel compelled to get some of the ones i really like again in paperback later :)
Current Mood: geekygeeky
Brian Johnson175560 on May 20th, 2005 04:52 pm (UTC)
Pointer cast?
DonAithnendonaithnen on May 20th, 2005 10:05 pm (UTC)
The problem is that BYTE* is an array of, well, bytes, while CComBSTR is an array of wide chars, plus CComBSTR also has a long at the begining stating how long the array is. And actually what i said is true for BSTRs, which CComBSTRs are wrappers for so presumably they have more stuff to worry about. So i'm pretty sure a straight pointer cast would have very odd if not completly broken results.
Brian Johnson175560 on May 21st, 2005 02:54 pm (UTC)
OK, that makes sense. Can you cast the BYTE * to a char *, so that you avoid the memcpy()?
Brian Johnson175560 on May 21st, 2005 02:55 pm (UTC)
Or, better yet, cast it to a const char *.
Brian Johnson175560 on May 21st, 2005 03:00 pm (UTC)
Ooh! Ooh! Ooh! I just remembered that this is what the C++ operator reinterpret_cast is for!

BYTE *b = ...;
const char *str = reinterpret_cast
[Error: Irreparable invalid markup ('<const [...] *>') in entry. Owner must fix manually. Raw contents below.]

Ooh! Ooh! Ooh! I just remembered that this is what the C++ operator reinterpret_cast is for!

BYTE *b = ...;
const char *str = reinterpret_cast<const char *>(b);

(Sorry for the reply-spam... I'm still waking up, brain works slowly...)