Solved

String to Guid

Posted on 2003-10-27
6
1,668 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  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 …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

732 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