473,809 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 = ("7B41464136344 430382D35413242 2D34");
//how do i get g = s1?!
}

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

Aug 4 '05 #1
3 18293
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 = ("7B41464136344 430382D35413242 2D34");
//how do i get g = s1?!
_GUID& _GUID::operator =(std::string guid) throw(invalid_g uid) {
// 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 = ("7B41464136344 430382D35413242 2D34");
//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 = ("7B41464136344 430382D35413242 2D34");
//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
11261
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 not know how to translate the ReDim that occurs there into C#. Or wither this will actually give me what I'm looking for. The code I'm posting seems to work although I don't know how to set the length of the name correctly in the...
2
29517
by: jiangyh | last post by:
hi there : I have a question about how to convert Type to DbType? thanks a lot. jiangyh
7
2371
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 instance). MIDL_INTERFACE("7FD52380-4E07-101B-AE2D-08002B2EC713") IPersistStreamInit : public IPersist { public: virtual HRESULT STDMETHODCALLTYPE IsDirty( void) = 0; virtual HRESULT STDMETHODCALLTYPE Load(/* */ LPSTREAM pStm) =
1
1603
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 http://www.ureader.com
10
2624
by: Crirus | last post by:
Is there a function that return some random ID like string alphanumeric? Like this: A35sDsd1dSGsH Thanks Crirus
2
10461
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 = GetConverter(SearchGUID).ConvertFrom(SearchID) GetConverter is used with the following Imports Object: Imports System.ComponentModel.TypeDescriptor Is there a different way to convert a string to a GUID that is compliant
1
4128
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 dashes. client.PartyHomeAddressID = new Guid(contact.Substring(1542, 36).Trim());
0
3120
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! Here is the code: ======
9
2867
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 dbcc_devicetype; DWORD dbcc_reserved; GUID dbcc_classguid;
0
10640
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7662
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.