473,473 Members | 4,204 Online
Bytes | Software Development & Data Engineering Community
Create 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_MACHINE,
L"SOFTWARE\\Microsoft\\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(hKey, L"fjkGUID", 0, REG_BINARY , (BYTE*)Myguid, 16 );
// 7

}

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

Thanks ...
Frits Janse Kok
Jul 22 '05 #1
10 3273
"Frits JK" <fj*@eb.nl> wrote in message
news:5f****************@amsnews05.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_MACHINE,
L"SOFTWARE\\Microsoft\\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(hKey, 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<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

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.west.earthlink.net...
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

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"0123456789ABCDEF";
return std::find(digits, 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( "A1FF01999ED3" )
//-----------------------------------
function Hex2Bin( HexString )

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

for i=1 to len(HexString) step 2

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

n2=asc(substr(HexString,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.west.earthlink.net...
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"0123456789ABCDEF";
return std::find(digits, 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( "A1FF01999ED3" )
std::string BinString = Hex2Bin( "A1FF01999ED3" );

//-----------------------------------
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(HexString,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(HexString,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_back(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<iomanip> 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<char>(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
Dear David,

This code is working fine !!!
Thank you very much for every thing you did for me.
In the last days I have learned a lot of new C++ syntax.
For instance I did not know about str::string ( I allways used CString from
MFC ).
This weekend I will try to find some good C++ books.

Ones more : " thank you very much "

Greetings from The Netherlands, Europe
Frits Janse Kok
Jul 22 '05 #11

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

Similar topics

11
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...
1
by: agrsaurabh | last post by:
Code Sample:- ATL Class class CAtl : public IA, Public IB
4
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...
5
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...
2
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...
2
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...
9
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...
2
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...
8
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...
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...
1
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...
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.