From GUID to char* via a stream:
// This is supposed to reset the state on the ostream after its done,
// but I'm not 100% certain it does so correctly, nor am I 100% certain
// that it doesn't wipe out error state info.
std::ostream& operator<<(std::ostream& lhs, GUID const & rhs)
{
long nFlags = lhs.flags();
std::streamsize nWidth = lhs.width();
char cFill = lhs.fill();
lhs << std::hex << std::setfill('0') ;
lhs << std::setw(8) << rhs.Data1 << "-"
<< std::setw(4) << rhs.Data2 << "-" << rhs.Data3 << "-";
lhs << std::setw(2) << (unsigned long) rhs.Data4[0] << (unsigned
long) rhs.Data4[1] << "-";
for (int i = 2; i < 8; ++i)
lhs << std::setw(2) << (unsigned long) rhs.Data4[i];
lhs.flags(nFlags);
lhs.width(nWidth);
lhs.fill(cFill);
return lhs;
}
Then, you can use it like this:
GUID guid; // From wherever it is you get it
std::ostringstream oss;
oss << guid;
std::string s_guid = oss.str();
// Or, if you absolutely must have a char* (not recommended):
LPSTR sz = new char[39]; // I recommend double-checking the length
strncpy(sz, oss.str().c_str(), 39);
// ...
delete[] sz;
--
Craig Powers
MVP - Visual C++
By reading this I know how few C++ I know.
*Bows*
"Craig Powers" <eni...@hal-pc.org> escribió en el mensaje
news:3EDDF823...@hal-pc.org...
--
Cheers
Check Abdoul [ VC++ MVP ]
-----------------------------------
"Fernando Ortigosa" <fernando...@e2000fi.com> wrote in message
news:e6UJPGpK...@TK2MSFTNGP12.phx.gbl...
Hmmm. Just Adding:
USES_CONVERSION;
CLSIDFromString(T2OLE(tchTypeCLSID),&Info.guid);
where tchTypeCLSID is a TCHAR containing the CLSID string
and Info is an structure (where I store some typelib info) whose guid member
belongs to the GUID data type
Apart of this I had to add:
#include <atlbase.h>
#include <atlcom.h>
#include <atlconv.h>
using namespace ATL;
"CheckAbdoul" <check...@nospam.mvps.org> escribió en el mensaje
news:#17vHRqK...@TK2MSFTNGP12.phx.gbl...
Just noticed, this doesn't put in bracketing '{' and '}'. If you
need them, that should be added.
e.g.
// This line before any of the other insertions above...
lhs << '{';
// This line after the insertions but before the cleanup...
lhs << '}';
For my purposes, I was generating __declspec(uuid) strings, so I
didn't want the braces.
I have solved it at this time. But thank you very much for your time and for
your FAST answer.
Thanks a lot.
"Craig Powers" <eni...@hal-pc.org> escribió en el mensaje
news:3EDE1B90...@hal-pc.org...
I do not think you need all the atl includes here. Just try
#include <objbase.h>
TCHAR* sGuid = { TEXT("{AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE}") };
CLSID clsId = {0};
CLSIDFromString(sGuid,&clsId);
--
Cheers
Check Abdoul [ VC++ MVP ]
-----------------------------------
"Fernando Ortigosa" <fernando...@e2000fi.com> wrote in message
news:OyRCDMrK...@TK2MSFTNGP12.phx.gbl...
Anyway. Could you tell me if I am including too much stuff in my project? =>
Thanks <=
"CheckAbdoul" <check...@nospam.mvps.org> escribió en el mensaje
news:#MoJNdrK...@TK2MSFTNGP11.phx.gbl...
then you may want to use the _bstr_t helper class to get from the char * representation to a wide character format.
Something like this:
/* ****************************************** */
GUID myGuid;
char *strGUID[900];
GetGuidCharFromSomewhere(strGUID);
_bstr_t bstrBUID(strGUID);
CLSIDFromString ((wchar_t *)bstrGUID,&myGuid);
...
DoSomethingWithMyNewGuid(myGuid);
/* ****************************************** */
regards
roy fine
"Fernando Ortigosa" <fernando...@e2000fi.com> wrote in message news:ukQCeirK...@TK2MSFTNGP12.phx.gbl...
You shouldn't need anything more than <atlconv.h> to use the conversion
macros. I don't think you even need the namespace -- since they're
macros, namespaces aren't an issue.
It is a bit of "bad work" from my part. As I didnt know which files I have
to include to "enable" that function, and it looked like ATL ( I have to
read several tutorials... :(, C++ has changed very much since my beloved 16
bits C++ ), so I created a new ATL project and copied the #include lines to
my current project.
I think that I will try with only <atlbase.h> and <atlconv.h>.
Thanks for the advice and the help.
"Craig Powers" <eni...@hal-pc.org> escribió en el mensaje
news:3EDE3B71...@hal-pc.org...
The thing you told me is a good thing to know, but it isnt my case. Anyway.
I do want to thank you for your interest and I will keep this on mind if I
ever need it (I bet I will).
Thanks
--
_____________________________
Fernando Jose Ortigosa Alvarez
<fernando...@e2000fi.com>
E2000 Financial Investments S.A.
Area de Servicios de Información
_____________________________
"Roy Fine" <John...@nomail.org> escribió en el mensaje
news:uIH$HFsKDH...@TK2MSFTNGP09.phx.gbl...
Thanks a lot!
"Fernando Ortigosa" <fernando...@e2000fi.com> escribió en el mensaje
news:##uNQRzKD...@TK2MSFTNGP11.phx.gbl...