0

I'm working with code where a GUID is defined like this:

DEFINE_GUID( GUID_DEVINTERFACE_USB_DISK,
             0x53f56307L, 0xb6bf, 0x11d0, 0x94, 0xf2,
             0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b );

I want to change the value and use a different class GUID from here where it is is defined as {A5DCBF10-6530-11D2-901F-00C04FB951ED}

How to I set to this value or create a new GUID variable which is set to this value?

Based on another answer here I tried but that doesn't work

GUID USB_GUID = GUID {"{A5DCBF10-6530-11D2-901F-00C04FB951ED}"}

Note, this GUID is used by a windows API later in my code:

if ( ! SetupDiEnumDeviceInterfaces( hDevInfo, 
                                    NULL,
                                    &GUID_DEVINTERFACE_USB_DISK,
                                    dwIndex, &spdid ))
break;
Community
  • 1
  • 1
zar
  • 11,361
  • 14
  • 96
  • 178

1 Answers1

1

Check this QUuid class (as you are tagging this question as related to Qt):

It has threesconstructors that may solve your problem:

QUuid(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8)
QUuid(const QString & text)
QUuid(const GUID & guid)

I think both QUuid( "0xA5DCBF10-6530-11D2-901F-00C04FB951ED" ) and QUuid( GUID_DEVINTERFACE_USB_DISK ) should create you a QUuid correctly setup.

If you need to convert the QUUid back to a GUID (to send it to SetupDiEnumDeviceInterfaces) for instance, according to this post, you simply need to do:

QUuid boo( "0xA5DCBF10-6530-11D2-901F-00C04FB951ED" );
GUID uid = static_cast<GUID>(boo);
Community
  • 1
  • 1
jpo38
  • 20,821
  • 10
  • 70
  • 151
  • I need it to feed it to a windows API namely `SetupDiEnumDeviceInterfaces` I don't see any conversion to GUID if I use it! – zar Nov 19 '15 at 20:48
  • Why you did not mention that in the OP? – jpo38 Nov 19 '15 at 20:50
  • This worked but I noticed there is `operator` function `GUID` which should return windows GUID but I have't heard of a function and operator before. Simplying call it does't build. Any idea how to make that work? – zar Nov 19 '15 at 21:14
  • 1
    It's a cast operator, that can be used this way: `GUID uid = (GUID)boo` or `GUID uid = static_cast(boo)`. So as you see, the static cast will use this operator. – Felix Nov 19 '15 at 21:30
  • @zadane: In my post I'm giving the code converting QUuid to GUID. – jpo38 Nov 19 '15 at 21:48