473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
3 18238
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeffrey B. Holtz | last post by:
I'm trying to get the Name of the USB device pluged in from the RegisterDeviceNotification that I've used P/Invoke to marshal. I have seen a similar posting on the VisualBasic newgroups but I do...
2
by: jiangyh | last post by:
hi there : I have a question about how to convert Type to DbType? thanks a lot. jiangyh
7
by: Charles Law | last post by:
Can anyone convert the following C++ interface definition to VB.NET? I have had a go, but I cannot make the Load function work and the IsDirty function gives an error (Object not set to an...
1
by: guoqi zheng | last post by:
I have a string, e.g. DC238D6668E341529BBA0F960C661399 which was a guid before. I need to convert this back to a datatype Guid. How can I do this??? regards, Guoqi Zheng...
10
by: Crirus | last post by:
Is there a function that return some random ID like string alphanumeric? Like this: A35sDsd1dSGsH Thanks Crirus
2
by: jmhmaine | last post by:
I have the the folllowing code that works when Option Strict is Off: Dim SearchID as string = "2F0B92F1-23E5-4CFA-B8D6-FAFEADE90EBC" Dim SearchGUID As Guid SearchGUID =...
1
by: Wolf | last post by:
Hi I am trying to set a property(PartyHomeAddressID) = to a guid in a ini file. But everytime when the ini file has an empty guid it breaks with an error tellin me a guid is 32 char long with 4...
0
by: MarcoDieleman | last post by:
Hello you all, I have this code that is written in MS Transact-SQL and I need to convert it to work with Oracle. Can anyone please help??? I need the code for a VBscript project. Thanks! ...
9
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i am a little stuck here, how do i convert this from C Structure to an structure in C# that can be marshalled: typedef struct _DEV_BROADCAST_DEVICEINTERFACE { DWORD dbcc_size; DWORD...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.