Convert hex string into GUID without using MFC/ATL/.NET

J

James DeClerk

Hi everyone.

I have a guid that's in string format. I would like to convert it to a
GUID. I'm doing this on the unix platform, so it will apply to only to
GCC/G++.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

typedef struct _GUID
{
unsigned long l;
unsigned short s1;
unsigned short s2;
unsigned char c[8];
} GUID;

int main() {

GUID g;
//String is in hex format.
string s1 = ("7B41464136344430382D354132422D34");
//how do i get g = s1?!
}

Also, is working with GUIDs without using MFC/ATL/.NET a viable
strategy?
 
T

Tobias Blomkvist

James DeClerk sade:
Hi everyone.

I have a guid that's in string format. I would like to convert it to a
GUID. I'm doing this on the unix platform, so it will apply to only to
GCC/G++.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

typedef struct _GUID
{
unsigned long l;
unsigned short s1;
unsigned short s2;
unsigned char c[8];
} GUID;

int main() {

GUID g;
//String is in hex format.
string s1 = ("7B41464136344430382D354132422D34");
//how do i get g = s1?!

_GUID& _GUID::eek:perator=(std::string guid) throw(invalid_guid) {
// make sure the guid-string is valid; right size etc
// extract substrings and convert accordingly
return *this;
}
}

Also, is working with GUIDs without using MFC/ATL/.NET a viable
strategy?

Depends on your intended usage. If you need to secure a long unique id,
then why not? If your universe is much smaller, perhaps a 32-bit id
will be sufficient, which will also be easier to calculate on.

Tobias
 
S

Serge Skorokhodov (216716244)

James said:
Hi everyone.

I have a guid that's in string format. I would like to convert it to a
GUID. I'm doing this on the unix platform, so it will apply to only to
GCC/G++.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

typedef struct _GUID
{
unsigned long l;
unsigned short s1;
unsigned short s2;
unsigned char c[8];
} GUID;

int main() {

GUID g;
//String is in hex format.
string s1 = ("7B41464136344430382D354132422D34");
//how do i get g = s1?!
}

Also, is working with GUIDs without using MFC/ATL/.NET a viable
strategy?
Actually, it doesn't matter on Win32. rpc api provides Uuid*
family of functions for obtaining GUIDs and converting them
to/from string/binary form. I believe that MFC/ATL/.NET just use
this service through rpc api (look up in msdn for details).

Just one note though. Win32 used string guid/uuid representation
with dashes: xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxx. Isn't it
standard in unix world as well?
 
L

Larry I Smith

James said:
Hi everyone.

I have a guid that's in string format. I would like to convert it to a
GUID. I'm doing this on the unix platform, so it will apply to only to
GCC/G++.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

typedef struct _GUID
{
unsigned long l;
unsigned short s1;
unsigned short s2;
unsigned char c[8];
} GUID;

int main() {

GUID g;
//String is in hex format.
string s1 = ("7B41464136344430382D354132422D34");
//how do i get g = s1?!
}

Also, is working with GUIDs without using MFC/ATL/.NET a viable
strategy?

For linux, do 'man uuidgen', or see:

http://linux.about.com/library/cmd/blcmdl1_uuidgen.htm
http://linux.about.com/library/cmd/blcmdl3_libuuid.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,951
Messages
2,570,113
Members
46,699
Latest member
Abigail89S

Latest Threads

Top