Jessy D. Exum

I learned C++ really quickly and don't know as much about all the data types as I should. I don't know how to use RegSetValue correctly because the data it takes in is type BYTE*. I need to put three values in different locations:

DWORD:0x00000001
An IP address
And a path to an executable


The problem with this is that I have no idea how to assign these values to a byte, and I am not really even sure what a '*' in this context means (I know that '[]' makes an array). I have tried everything I can think of from defining constant char* values to casting DWORD values. I need to know how to use byte* data to write correct values into the registry as opposed to '01' which the regeditor doesn't like!


Re: Visual C++ General RegSetValue problem, don't know how to use byte datatype

TilakGopi

Hi,

Check the code snippet below for the usage of RegSetValueEx

-------------------------

BOOL setKeyAndValue(const char* szKey,

const char* szSubkey,

const char* szValue)

{

HKEY hKey;

char szKeyBuf[1024] ;

// Copy keyname into buffer.

strcpy(szKeyBuf, szKey) ;

// Add subkey name to buffer.

if (szSubkey != NULL)

{

strcat(szKeyBuf, "\\") ;

strcat(szKeyBuf, szSubkey ) ;

}

// Create and open key and subkey.

long lResult = RegCreateKeyEx(HKEY_CLASSES_ROOT ,

szKeyBuf,

0, NULL, REG_OPTION_NON_VOLATILE,

KEY_ALL_ACCESS, NULL,

&hKey, NULL) ;

if (lResult != ERROR_SUCCESS)

{

return FALSE ;

}

// Set the Value.

if (szValue != NULL)

{

RegSetValueEx(hKey, NULL, 0, REG_SZ,

(BYTE *)szValue,

strlen(szValue)+1) ;

}

RegCloseKey(hKey) ;

return TRUE ;

}

------------------------

also see the down-half of this web page :

http://www.codeproject.com/tools/phPathBreaker.asp df=100&forumid=73717&exp=0&select=873647

Thanx,

Ch.T.Gopi Kumar






Re: Visual C++ General RegSetValue problem, don't know how to use byte datatype

Jessy D. Exum

Thanks a lot, your code does do what I need, but I forgot to post the solution I came up with just a while ago. I asked a friend what the heck a * means and he mocked my for a while, finally telling me what they ment. I then went online and found out everything I could about pointers and wrote this:

byte* String2LongByte(std::string sInput, int* iOutLength){

*iOutLength = (sInput.length()+1)*2;

std::stringstream ssStream;

byte* temp = (byte *)malloc(*iOutLength);

int iStrIterate = 0;

for(int i = 0; i < (*iOutLength-2); i++){

if((i%2) == 0){

if(sInput.substr(iStrIterate, 1) == " "){

tempIdea = 0x20;

}else{

ssStream << sInput.substr(iStrIterate, 1);

ssStream >> tempIdea;

}

iStrIterate++;

}else{

tempIdea = 0;

}

}

temp[*iOutLength-1] = 0;

temp[*iOutLength-2] = 0;

return temp;

}

I just pass what I need to be a byte into this function and it returns a byte with all the necessary 0x00 values for the Unicode the registry uses!

Thanks a lot for your help anyway, I really appreciate your courtesy!





Re: Visual C++ General RegSetValue problem, don't know how to use byte datatype

TilakGopi

Thank you & Welcome ,

Best Regards,

Ch.T.Gopi Kumar.