By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,959 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,959 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?

Aug 4 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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::operator=(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
--
IMPORTANT: The contents of this email and attachments are confidential
and may be subject to legal privilege and/or protected by copyright.
Copying or communicating any part of it to others is prohibited and may
be unlawful.
Aug 4 '05 #2

P: n/a
James DeClerk wrote:
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?

--
Serge
Aug 6 '05 #3

P: n/a
James DeClerk wrote:
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
Aug 6 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.