Solved

String to Guid

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

937 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

10 Experts available now in Live!

Get 1:1 Help Now