473,796 Members | 2,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to write GUID to register ?


Hallo,

I have to write a GUID to the register but I don't know to convert to
hexadecimal.
I have tried several things but I am shore that line 5 and 6 are not
correct.
//--------------------------------------------------------------------------
----------

if (RegCreateKeyEx (HKEY_LOCAL_MAC HINE,
L"SOFTWARE\\Mic rosoft\\MSMQ\\S impleClient\\" , 0, NULL, 0, 0, NULL, &hKey,
&disp)== ERROR_SUCCESS)

{

GUID pguid ; // 2
CSTUtil su; // 3
su.CoCreateGuid ( &pguid); // 4
char Myguid[50]; // 5 ??
sprintf( Myguid, "%#8x%#4x%#4x%s ", pguid.Data1, pguid.Data2,
pguid.Data3, pguid.Data4 ); // 6 ??
RegSetValueEx(h Key, L"fjkGUID", 0, REG_BINARY , (BYTE*)Myguid, 16 );
// 7

}

//--------------------------------------------------------------------------
------

Thanks ...
Frits Janse Kok
Jul 22 '05 #1
10 3299
"Frits JK" <fj*@eb.nl> wrote in message
news:5f******** ********@amsnew s05.chello.com. ..

Hallo,

I have to write a GUID to the register but I don't know to convert to
hexadecimal.


A win32 newsgroup would be more appropriate, but try:

http://www.google.com/search?q=win32...1+Data2+printf
Jul 22 '05 #2
On Wed, 16 Jun 2004 18:24:01 GMT in comp.lang.c++, "Frits JK"
<fj*@eb.nl> wrote,
sprintf( Myguid, "%#8x%#4x%#4x%s ", pguid.Data1, pguid.Data2,
pguid.Data3, pguid.Data4 ); // 6 ??


Been using streams so long I had to get out an old book to review printf
formats. You should too. I doubt if you want any # in that. Make sure
you are getting the string built right before proceeding further.

Try perhaps:

ostringstream format_guid;
format_guid << hex << setfill('0') << setw(8) << pguid.Data1
<< setw(4) << pguid.Data2
etc.

then use result form
format_guid.str ().c_str()
Jul 22 '05 #3
ak
On Wed, 16 Jun 2004 18:24:01 GMT, "Frits JK" <fj*@eb.nl> wrote:

Hallo,

I have to write a GUID to the register but I don't know to convert to
hexadecimal .
I have tried several things but I am shore that line 5 and 6 are not
correct.
//--------------------------------------------------------------------------
----------

if (RegCreateKeyEx (HKEY_LOCAL_MAC HINE,
L"SOFTWARE\\M icrosoft\\MSMQ\ \SimpleClient\\ " , 0, NULL, 0, 0, NULL, &hKey,
&disp)== ERROR_SUCCESS)

{

GUID pguid ; // 2
CSTUtil su; // 3
su.CoCreateGuid ( &pguid); // 4
char Myguid[50]; // 5 ??
sprintf( Myguid, "%#8x%#4x%#4x%s ", pguid.Data1, pguid.Data2,
pguid.Data3 , pguid.Data4 ); // 6 ??
RegSetValueEx(h Key, L"fjkGUID", 0, REG_BINARY , (BYTE*)Myguid, 16 );
// 7

}

//--------------------------------------------------------------------------
------

Thanks ...
Frits Janse Kok


if you are using MSC7:

try using the CRegKey class instead for registry handling, it is more convenient
it has a function called SetGUIDValue which should do the trick, check out
online doc on that. e.g. SetGUIDValue( L"fjkGUID", pguid );
hth
ak


Jul 22 '05 #4
On Thu, 17 Jun 2004 19:48:48 +0800 in comp.lang.c++, ak
<ak@workmail<do t>com> wrote,
if you are using MSC7:

try using the CRegKey class instead for registry handling, it is more


This comment is OFF TOPIC in comp.lang.c++. Please keep your answers to
standard portable C++ content and avoid proprietary API discussions.

See the welcome message posted twice per week in comp.lang.c++ or
available at http://www.slack.net/~shiva/welcome.txt

Jul 22 '05 #5

Thanks for all the suggestions, but up till now I don't have a real solution
for something that must be easy for a real C++ programmer.
The problem is that I have worked many years with xBase language's and
started only some weeks

ago with C++ because I have to build a small application in C++ for the
pocket PC


The problem on this moment is that I have to convert a 64 byte Unicode
string to a 16 byte binary string

for instance I need a chr(245) and I have a chr(70) + chr(0)+ chr(53) +
chr(0) = F5

In xBase I can write in 2 minutes a do while loop to convert this string but
on this moment I don't have the know-how to do this in C++



Frits Janse Kok.
"David Harmon" <so****@netcom. com.invalid> schreef in bericht
news:40******** ******@news.wes t.earthlink.net ...
On Thu, 17 Jun 2004 19:48:48 +0800 in comp.lang.c++, ak
<ak@workmail<do t>com> wrote,
if you are using MSC7:

try using the CRegKey class instead for registry handling, it is more


This comment is OFF TOPIC in comp.lang.c++. Please keep your answers to
standard portable C++ content and avoid proprietary API discussions.

See the welcome message posted twice per week in comp.lang.c++ or
available at http://www.slack.net/~shiva/welcome.txt

Jul 22 '05 #6
On Thu, 17 Jun 2004 23:09:02 GMT in comp.lang.c++, "Frits JK"
<fj*@eb.nl> wrote,
The problem on this moment is that I have to convert a 64 byte Unicode
string to a 16 byte binary string
What is the content of the Unicode string? Hexadecimal? In solving
such problems, I find that the most important thing is to be very clear
about what you start with and what you want to end up with.

Your original question looks more like converting the other way.
for instance I need a chr(245) and I have a chr(70) + chr(0)+ chr(53) +
chr(0) = F5


This example on my system prints 245 = f5.
#include <iostream>
#include <iomanip>
#include <algorithm>

inline int hex1(wchar_t ch)
{
static const wchar_t digits[] = L"0123456789ABC DEF";
return std::find(digit s, digits+16, ch)
- digits;
}

inline int hex2(wchar_t ch1, wchar_t ch2)
{
return hex1(ch1) * 16 + hex1(ch2);
}

int main(void)
{
wchar_t s[] = L"F5";
int bits = hex2(s[0], s[1]);
std::cout << bits << " = " << std::hex << bits;
return 0;
}

Perhaps if you included your XBase fragment then the answers might more
exactly fit your intentions, style, etc.
Jul 22 '05 #7
ak
On Thu, 17 Jun 2004 18:33:45 GMT, David Harmon <so****@netcom. com.invalid>
wrote:
On Thu, 17 Jun 2004 19:48:48 +0800 in comp.lang.c++, ak
<ak@workmail< dot>com> wrote,
if you are using MSC7:

try using the CRegKey class instead for registry handling, it is more


This comment is OFF TOPIC in comp.lang.c++. Please keep your answers to
standard portable C++ content and avoid proprietary API discussions.

See the welcome message posted twice per week in comp.lang.c++ or
available at http://www.slack.net/~shiva/welcome.txt


yes master
Jul 22 '05 #8
Perhaps if you included your XBase fragment then the answers might more
exactly fit your intentions, style, etc.
BinString := Hex2Bin( "A1FF01999E D3" )
//-----------------------------------
function Hex2Bin( HexString )

Local n1,n2,i, result:=""

for i=1 to len(HexString) step 2

n1=asc(substr(H exString,i,1)
n1=if(n1>57 , n1-48 , n1-55 )

n2=asc(substr(H exString,i+1,1)
n2=if(n2>57 , n2-48 , n2-55 )

Result+= chr(16*n1 + n2 )
next i
return Result
//--------------------------------

Here you see my xBase example, I think that your example gives the same
result.
I am still studing on the sintax or the command line " std::cout <<
bits << " = " << std::hex << bits; "
On this moment I don't realy understand what this means.
Could you please tell me the equivalents of the xBase functions :
asc ( ) // returns the ASCII value of a character
chr( ) // returns 1 character
substr( String , nStart, nCount) // I use EVC++ and MFC
Thanks you all
Frits Janse Kok


"David Harmon" <so****@netcom. com.invalid> schreef in bericht
news:40******** *******@news.we st.earthlink.ne t...
On Thu, 17 Jun 2004 23:09:02 GMT in comp.lang.c++, "Frits JK"
<fj*@eb.nl> wrote,
The problem on this moment is that I have to convert a 64 byte Unicode
string to a 16 byte binary string


What is the content of the Unicode string? Hexadecimal? In solving
such problems, I find that the most important thing is to be very clear
about what you start with and what you want to end up with.

Your original question looks more like converting the other way.
for instance I need a chr(245) and I have a chr(70) + chr(0)+ chr(53) +
chr(0) = F5


This example on my system prints 245 = f5.
#include <iostream>
#include <iomanip>
#include <algorithm>

inline int hex1(wchar_t ch)
{
static const wchar_t digits[] = L"0123456789ABC DEF";
return std::find(digit s, digits+16, ch)
- digits;
}

inline int hex2(wchar_t ch1, wchar_t ch2)
{
return hex1(ch1) * 16 + hex1(ch2);
}

int main(void)
{
wchar_t s[] = L"F5";
int bits = hex2(s[0], s[1]);
std::cout << bits << " = " << std::hex << bits;
return 0;
}

Perhaps if you included your XBase fragment then the answers might more
exactly fit your intentions, style, etc.

Jul 22 '05 #9
Please don't top post.

On Fri, 18 Jun 2004 18:17:11 GMT in comp.lang.c++, "Frits JK"
<fj*@eb.nl> wrote,
Here you see my xBase example, I think that your example gives the same
result.
And here is a mostly line-by-line translation into C++. This may not be
the best C++ code, but I provide it in order to show some (hopefully)
comparable concepts.
BinString := Hex2Bin( "A1FF01999E D3" )
std::string BinString = Hex2Bin( "A1FF01999E D3" );

//-----------------------------------
function Hex2Bin( HexString )
std::string Hex2Bin( std::string const & HexString )
{
Local n1,n2,i, result:=""
int n1, n2, i;
std::string result;
for i=1 to len(HexString) step 2
for(i = 0; i < HexString.size( ); i+=2) {
n1=asc(substr(H exString,i,1)
n1 = HexString[i];
n1=if(n1>57 , n1-48 , n1-55 )
n1 = (n1>57) ? n1-48 : n1-55;
// these magic numbers are very error-prone.
n2=asc(substr(H exString,i+1,1)
n2 = HexString[i+1];
n2=if(n2>57 , n2-48 , n2-55 )
n2 = (n2>57) ? n2-48 : n2-55;
Result+= chr(16*n1 + n2 )
result.push_bac k(16*n1 + n2);
next i
}
return Result
return result;
}
//--------------------------------

I am still studing on the sintax or the command line " std::cout <<
bits << " = " << std::hex << bits; "
On this moment I don't realy understand what this means.
In particular, std::hex comes from #include<iomani p> and sets flags in
the cout stream to tell it to use hexadecimal format for following
integer output. The flags can be reset with std::dec.
Could you please tell me the equivalents of the xBase functions :
asc ( ) // returns the ASCII value of a character
chr( ) // returns 1 character
Single chars are an integral type in C and C++ and you can often just
let the default conversions happen like you will spot in my example
above. In case you need to force a conversion, the most foolproof way
is also the most work to write:
int i = static_cast<int >(ch);
char ch = static_cast<cha r>(i);
substr( String , nStart, nCount) // I use EVC++ and MFC


I use std::string from the standard library. It has a substr member
function that you can look up in any decent C++ reference, for instance
section 20.3.13 of Stroustrup _The C++ Programming Language, Third Ed._

Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2360
by: Dave Anderson | last post by:
Consider the following: var GUID = Server.CreateObject("Scriptlet.TypeLib").GUID Let's assume GUID is {9A46FCC9-A7A1-4C96-9394-B1A966CEC081}. I happened to notice that if I concatenate this with any other string value, Response.Write aborts after the 38th character of the GUID (the closing brace):
1
3249
by: agrsaurabh | last post by:
Code Sample:- ATL Class class CAtl : public IA, Public IB
4
15656
by: Louis Frolio | last post by:
Greetings All, I have read many upon many articles here regarding GUID data types and uniqueness. There have been many opinions regarding the effectiveness of GUID's and when they should/should not be used. However, every article strongly implies, if it does not state it outright, that GUID's are always unique. My question is this, what happens if you have a database that uses GUID's and the NIC is changed out on the box? From what I...
5
6342
by: rcolby | last post by:
Evening, Wondering if someone can point me in the right direction, on how I would compare a system.guid with a system.byte. system.guid (pulled from sql server table with a data type of uniqueidentifier, originally taken from objectGUID from active directory domain)
2
4201
by: Lucas Tam | last post by:
Hi all, I'm using the command GetType(MyObject).GUID to return a GUID. Is the GUID a CRC type calculation on the object, or is it a pre-assigned value on the object? I was hoping to have a way to do a CRC type calculation on an object to see if it has changed or has been tampered with. Thanks.
2
1545
by: MR | last post by:
i am developing a client C# application that utilized a legacy COM object. For development, I cannot use the object because it has specific hardware requirements. Therefore i would like to write a stub or "emulator" for this COM object, preferably i C# but C++ or VB.NET would work too. The idea is to be able to use this object in development, then in production (when the hardware is available) just regsvr32 the "real" object and use that...
9
3964
by: Cylix | last post by:
The following is a c# code about using browser helper object(BHO) anyone know in VB.NET? public interface IObjectWithSite { int SetSite(object site); int GetSite(ref Guid guid, out IntPtr ppvSite);
2
2413
by: Ronald S. Cook | last post by:
Given that PenID is a Guid, is there a better way to write this? if (PenID.ToString() != "00000000-0000-0000-0000-000000000000") I thought I could do some sort of Guid.Empty check or something. Thanks, Ron
8
1148
by: Jonathan Wood | last post by:
Greetings, I often find myself writing public properties in my ASP.NET code and I need the ability to robustly handle cases where the property has not been set. So I often end up with code like this: public Guid PresenterID { get
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9525
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10221
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10169
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
9050
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
7546
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
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
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...
3
2924
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.