• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

Need some assistance configuring registry keys

Hi All,

I'm trying to programatically set registry keys to configure a Microsoft Access data source.  One problem I am having is after I set a REG_SZ key's value.  When I look at the key in the registry, the key's value shows up as "my keys value"...

Anyone know why there is a "..." after the key's value?  For some reason, this is not being read by the control panel's data source manager.

Here's my code:
*************************************************************
CString dbLocation = "C:\\database.mdb";
CString key = "Software\\ODBC\\ODBC.INI\\MY_DataSource";
HKEY hKey;
DWORD dwType = REG_SZ;

::RegCreateKeyEx(HKEY_LOCAL_MACHINE, key, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwType);
::RegSetValueEx(hKey, "DBQ", 0, REG_SZ, (const unsigned char*)(LPCTSTR)dbLocation, MAX_PATH);

*************************************************************
There are other keys but I did not include them as it would be repetitive.

Thanks for your help.
0
StanChart
Asked:
StanChart
1 Solution
 
jkrCommented:
>>::RegSetValueEx(hKey, "DBQ", 0, REG_SZ, (const unsigned char*)(LPCTSTR)dbLocation, MAX_PATH);

Here, you need to specify the *exact* length of the string, thus the '...' part. This should be

::RegSetValueEx(hKey, "DBQ", 0, REG_SZ, (const unsigned char*)(LPCTSTR)dbLocation, dbLocation.GetLength());
0
 
StanChartAuthor Commented:
You're the man!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now