WillieBotha
Programmer
Hi,
I am new to this forums as well as to Visual C++ so hello to all. I seem to have a strange problem here. What I did is I created a dll which writes values to the registry. Two of the values are written correctly and the other is gibberish. The code is as follows - I will indicate also where the code changes to gibberish. The variable that changes is UName :
long SYNCID::RegCreate(const char datastring[10])
{
HKEY HK,K;
char ClassString[3] = "CS";
LPCTSTR SubKeyName = "M&MInfo";
LPSTR U_Name="UserName";
LPSTR U_Path="UserPath";
LPSTR U_Folder="UserFolder";
LPSTR UName="UserName";
LPSTR UPath="UserPath";
LPSTR UFolder="UserFolder";
CUserIDInfo cid;
int i=0;
unsigned long *lp=NULL;
unsigned long return_value;
RetUserPath(UName,UPath,UFolder);
//Here the Value of UName is as it should be nl. Willie Botha
//CREATE THE REGISTRY KEY
return_value=RegCreateKeyEx(HKEY_CURRENT_CONFIG,
SubKeyName,
0, //reserved
ClassString,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&HK,
lp) ;
//Here the Value of UName changed to
if (return_value==ERROR_SUCCESS) {
SyncAddLogEntry("\n Info Key Created \n"
;
}
else
{
SyncAddLogEntry("\n Info Key Not Created \n"
;
}
SyncAddLogEntry("Testing This : "
;
SyncAddLogEntry((const char *)UName);
// OPEN KEY
/********************************************************************/
return_value=RegCreateKeyEx(HK,
datastring,
0, //reserved
ClassString,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&K,
lp) ;
if (return_value==ERROR_SUCCESS) {
SyncAddLogEntry("\n Serial Key Created \n"
;
}
else
{
SyncAddLogEntry("\n Serial Key Not Created \n"
;
}
/*******************************************************************/
//CREATE AND SET THE VALUE
return_value=RegSetValueEx(K, // handle of key to set value for
U_Name, // address of value to set
0, // reserved
REG_SZ, // flag for value type
(const unsigned char *)UName,
//(const unsigned char *)datastring, // address of value data
strlen(UName) // size of value data
);
SyncAddLogEntry("Testing Again : "
;
SyncAddLogEntry((const char *)UName);
if (return_value==ERROR_SUCCESS) {
SyncAddLogEntry("\n User Name Key Created"
;
}
else
{
SyncAddLogEntry("\n User Name Key Not Created"
;
}
return_value=RegSetValueEx(K, // handle of key to set value for
U_Path, // address of value to set
0, // reserved
REG_SZ, // flag for value type
(const unsigned char *)UPath,
//(const unsigned char *)datastring, // address of value data
strlen(UPath) // size of value data
);
if (return_value==ERROR_SUCCESS) {
SyncAddLogEntry("\n User Path Key Created"
;
}
else
{
SyncAddLogEntry("\n User Path Key Not Created"
;
}
return_value=RegSetValueEx(K, // handle of key to set value for
U_Folder, // address of value to set
0, // reserved
REG_SZ, // flag for value type
(const unsigned char *)UFolder,
//(const unsigned char *)datastring, // address of value data
strlen(UFolder) // size of value data
);
if (return_value==ERROR_SUCCESS) {
SyncAddLogEntry("\n User Folder Key Created"
;
}
else
{
SyncAddLogEntry("\n User Folder Key Not Created"
;
}
SyncAddLogEntry("\n"
;
return 0;
}
Thanks in advance,
Willie Botha
Programmer
Mead & McGrouther
South-Africa
I am new to this forums as well as to Visual C++ so hello to all. I seem to have a strange problem here. What I did is I created a dll which writes values to the registry. Two of the values are written correctly and the other is gibberish. The code is as follows - I will indicate also where the code changes to gibberish. The variable that changes is UName :
long SYNCID::RegCreate(const char datastring[10])
{
HKEY HK,K;
char ClassString[3] = "CS";
LPCTSTR SubKeyName = "M&MInfo";
LPSTR U_Name="UserName";
LPSTR U_Path="UserPath";
LPSTR U_Folder="UserFolder";
LPSTR UName="UserName";
LPSTR UPath="UserPath";
LPSTR UFolder="UserFolder";
CUserIDInfo cid;
int i=0;
unsigned long *lp=NULL;
unsigned long return_value;
RetUserPath(UName,UPath,UFolder);
//Here the Value of UName is as it should be nl. Willie Botha
//CREATE THE REGISTRY KEY
return_value=RegCreateKeyEx(HKEY_CURRENT_CONFIG,
SubKeyName,
0, //reserved
ClassString,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&HK,
lp) ;
//Here the Value of UName changed to
if (return_value==ERROR_SUCCESS) {
SyncAddLogEntry("\n Info Key Created \n"
}
else
{
SyncAddLogEntry("\n Info Key Not Created \n"
}
SyncAddLogEntry("Testing This : "
SyncAddLogEntry((const char *)UName);
// OPEN KEY
/********************************************************************/
return_value=RegCreateKeyEx(HK,
datastring,
0, //reserved
ClassString,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&K,
lp) ;
if (return_value==ERROR_SUCCESS) {
SyncAddLogEntry("\n Serial Key Created \n"
}
else
{
SyncAddLogEntry("\n Serial Key Not Created \n"
}
/*******************************************************************/
//CREATE AND SET THE VALUE
return_value=RegSetValueEx(K, // handle of key to set value for
U_Name, // address of value to set
0, // reserved
REG_SZ, // flag for value type
(const unsigned char *)UName,
//(const unsigned char *)datastring, // address of value data
strlen(UName) // size of value data
);
SyncAddLogEntry("Testing Again : "
SyncAddLogEntry((const char *)UName);
if (return_value==ERROR_SUCCESS) {
SyncAddLogEntry("\n User Name Key Created"
}
else
{
SyncAddLogEntry("\n User Name Key Not Created"
}
return_value=RegSetValueEx(K, // handle of key to set value for
U_Path, // address of value to set
0, // reserved
REG_SZ, // flag for value type
(const unsigned char *)UPath,
//(const unsigned char *)datastring, // address of value data
strlen(UPath) // size of value data
);
if (return_value==ERROR_SUCCESS) {
SyncAddLogEntry("\n User Path Key Created"
}
else
{
SyncAddLogEntry("\n User Path Key Not Created"
}
return_value=RegSetValueEx(K, // handle of key to set value for
U_Folder, // address of value to set
0, // reserved
REG_SZ, // flag for value type
(const unsigned char *)UFolder,
//(const unsigned char *)datastring, // address of value data
strlen(UFolder) // size of value data
);
if (return_value==ERROR_SUCCESS) {
SyncAddLogEntry("\n User Folder Key Created"
}
else
{
SyncAddLogEntry("\n User Folder Key Not Created"
}
SyncAddLogEntry("\n"
return 0;
}
Thanks in advance,
Willie Botha
Programmer
Mead & McGrouther
South-Africa