Solved

String to Guid

Posted on 2003-10-27
6
1,672 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

717 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