tags:

views:

165

answers:

1

I'm trying to convert a string to GUID with sscanf:

GUID guid;
sscanf( "11111111-2222-3333-4455-667788995511", "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
        &guid.Data1, &guid.Data2, &guid.Data3,
        &guid.Data4[0], &guid.Data4[1], &guid.Data4[2],
        &guid.Data4[3], &guid.Data4[4], &guid.Data4[5],
        &guid.Data4[6], &guid.Data4[7]);

However, in runtime, it fails and exits with "Error: Command failed". Why? How to fix it?

I do not want to compile with /clr so cannot use System.

+3  A: 

Where does "Error: Command failed" come from? It's not a standard error message...

You can use the UuidFromString function to do it in native C++.

Dean Harding
+1 -- Mote that UuidFromString is Windows-only.
Billy ONeal
I'm coding in haXe targeting c++, so maybe the error is from the haXe testing program... But the code in the question is in pure c++.When I use `UuidFromString("11111111-2222-3333-4455-667788995511",` it says `error C2664: 'UuidFromStringA' : cannot convert parameter 1 from 'const char *' to 'RPC_CSTR'` ...
Andy Li
@Billy: True, but he said he didn't want to use "/clr" which is also Windows-only, so I thought that was an OK assumption to make.
Dean Harding
@Andy: I believe a simple cast would work: `const char *str = "..."; UuidFromString((RPC_CSTR) str, `
Dean Harding
@codeka Oh, you're right. Thank you very much!
Andy Li
@codeka: That's why I +1'd :)
Billy ONeal