Solved

String to Guid

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

838 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