How to convert LPWSTR to GUID?

I work with the audio interfaces of Windows 7 and I hit a wall.

Basically, I need to take IAudioSessionControl2 * and get ISimpleAudioVolume * from it.

Now it looks like I can call IAudioSessionManager-> GetSimpleAudioVolume () using the value IAudioSessionControl2-> GetSessionInstanceIdentifier (...) . Please note that this is not explicitly stated as such in the docs, but this seems to be reasonable behavior.

The problem is, GetSimpleAudioVolume () accepts the GUID * and GetSessionInstanceIdentifier () spits out LPWSTR. Through debugging, I confirmed that the return'd value from GetSessionInstanceIdentifier () at least looks like a GUID.

So, the actual question is how to convert LPWSTR to GUID? I understand that this is pretty trivial if I go over to some managed code and use the built-in GUID , but there should be a C ++ way of doing this.


Well, these APIs definitely don't work the way I say what they do in the above text dump. However, the main question String → GUID answers, so I'm not going to delete the question.

+3
source share
2 answers

Give it a try CLSIDFromString. A CLSIDis actually defined as:

typedef GUID CLSID;

therefore you can use CLSIDFromStringto create a GUID. Here is a sample code:

LPWSTR guidstr;
GUID guid;

...

HRESULT hr = CLSIDFromString(guidstr, (LPCLSID)&guid);
if (hr != S_OK) {
    // bad GUID string...
    ...
}

A warning

, GUID, GUID. :

| String              | Returned Clsid                         |
|---------------------|----------------------------------------|
| "file"              | {00000303-0000-0000-C000-000000000046} | FileMoniker
| "AccessControlList" | {b85ea052-9bdd-11d0-852c-00c04fd8d503} |
| "ADODB.Record"      | {00000560-0000-0010-8000-00AA006D2EA4} |
| "m"                 | {4ED063C9-4A0B-4B44-A9DC-23AFF424A0D3} | Toolbar.MySearchDial

, , , .

: CLSIDFromString. IIDFromString .

+10

CLSIDFromString StringFromGUID2(), ... , CLSID.

-2

Source: https://habr.com/ru/post/1712613/


All Articles