Solved

String to Guid

Posted on 2003-10-27
6
1,658 Views
Last Modified: 2008-02-26
The url mentioned below is not existing at this time. Can anybody pl tell me how to convert a String to a const struct _GUID

Thanks
0
Comment
Question by:aparida123
6 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 9630657
aparida123:

> Can anybody pl tell me how to convert a String to a const struct _GUID

Try this:

     GUID GetGuidFromString( LPOLESTR lpsz )
     {
          GUID    guid;
          HRESULT hr;

          hr = ::CLSIDFromString( lpsz, &guid );
          return guid;
     }

For more info on CLSIDFromString, see this link:
     http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/cmf_a2c_3b3b.asp

Hope that helps,
Dex*
0
 

Author Comment

by:aparida123
ID: 9630723
I have a class id like this

49232000-16E4-426C-A231-62846947304B

So How can I declare the above as LPOLESTR . I mean to say

if I am declaring  

LPOLESTR lpsz ="49232000-16E4-426C-A231-62846947304B";
//it will not work as it needs to convert it to unsigned short.

How can i do it

Thanks
0
 
LVL 2

Accepted Solution

by:
onlyshiza earned 125 total points
ID: 9634418
>>  LPOLESTR lpsz ="49232000-16E4-426C-A231-62846947304B";
>>  //it will not work as it needs to convert it to unsigned short.

You need to add and "L" before you string literal like this:

LPOLESTR lpsz = L"49232000-16E4-426C-A231-62846947304B";
0
 
LVL 19

Assisted Solution

by:Dexstar
Dexstar earned 125 total points
ID: 9634667
aparida123:

1) The "accepted" way of writing a literal OLE string is with the OLESTR() macro.
2) I'm almost positive that you'll need {}'s around your GUID.

So, it would look like this:
     LPOLESTR lpsz = OLESTR("{49232000-16E4-426C-A231-62846947304B}");

Let me know what errors / problems you get.

Dex*
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10546209
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: onlyshiza {http:#9634418} & Dexstar {http:#9634667}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now