Click here to Skip to main content
15,914,013 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to pass an array to a COM method accept a VARIANT * Pin
songll10-May-07 8:26
songll10-May-07 8:26 
AnswerRe: How to pass an array to a COM method accept a VARIANT * Pin
James R. Twine10-May-07 8:48
James R. Twine10-May-07 8:48 
GeneralRe: How to pass an array to a COM method accept a VARIANT * Pin
CPallini10-May-07 9:00
mveCPallini10-May-07 9:00 
QuestionREGISTRY KEY: How to read/write Pin
J_E_D_I10-May-07 8:02
J_E_D_I10-May-07 8:02 
AnswerRe: REGISTRY KEY: How to read/write Pin
James R. Twine10-May-07 8:53
James R. Twine10-May-07 8:53 
QuestionRe: REGISTRY KEY: How to read/write Pin
J_E_D_I10-May-07 15:25
J_E_D_I10-May-07 15:25 
AnswerRe: REGISTRY KEY: How to read/write Pin
Richard Andrew x6410-May-07 18:11
professionalRichard Andrew x6410-May-07 18:11 
GeneralRe: REGISTRY KEY: How to read/write Pin
J_E_D_I12-May-07 7:27
J_E_D_I12-May-07 7:27 
Many thanks for the advice.

I have added the Advapi32.lib to the Additional Dependencies and tried to compile it (code below) but it results in many errors.

I would be very grateful for any advice.

#include "stdafx.h"
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
#include <iomanip>
using std::setprecision;

int _tmain(int argc, _TCHAR* argv[])
{

CString default_server;
CString default_root_dir;
CStringArray servers;
CStringArray rootdirs;
default_server = "";
default_root_dir = "";
servers.RemoveAll();
rootdirs.RemoveAll();
/* Read FTP server name and root directories from registry. GetRegistryList reads all the key values and fill in
the CString array */
HKEY hKey = GetRegistryKey( "Server" );
GetRegistryList( hKey, default_server, servers);
/* Now read it from array and add to a combo box */
for(int i=0; i<servers.getsize(); i++="" )
{
cstring="" str="servers[i].Left(" servers[i].find("#")="" );
combo-="">AddString( str );
}

Now, here is how to add one registry entry to the registry.

AddRegValue("Server", m_szftpServerName , m_szWebRootDir );

Now, here is how to delete a key and its corresponding value from the registry:

AddRegValue("Server", m_szftpServerName , m_szWebRootDir );
/* ************************************************************
Registry functions STARTS
************************************************************/
HKEY GetRegistryKey( CString str )
{
HKEY hViewerKey = NULL;
HKEY hSoftDirKey = NULL;
HKEY hCompanyKey = NULL;
HKEY hCompanyDirKey = NULL;
CString m_pszRegistryKey = "MIS Inc.";
CString m_pszProfileName;
m_pszProfileName = "Settings";
CString section = str;
//read from the registry...for default viewer
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSoftware, 0, KEY_WRITE|KEY_READ, &hSoftDirKey)
== ERROR_SUCCESS)
{
DWORD dw;
if (RegCreateKeyEx(hSoftDirKey, (LPCTSTR)m_pszRegistryKey, 0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE|KEY_READ, NULL, &hCompanyKey, &dw) == ERROR_SUCCESS)
{
if(RegCreateKeyEx(hCompanyKey, (LPCTSTR)m_pszProfileName, 0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE|KEY_READ, NULL, &hCompanyDirKey, &dw) == ERROR_SUCCESS)
{
RegCreateKeyEx(hCompanyDirKey, (LPCTSTR)section, 0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE|KEY_READ, NULL, &hViewerKey, &dw);
}
}
}
if (hCompanyKey != NULL)
RegCloseKey(hCompanyKey);
if (hSoftDirKey != NULL)
RegCloseKey(hSoftDirKey);
if (hCompanyDirKey != NULL)
RegCloseKey(hCompanyDirKey);
return hViewerKey;
}
BOOL GetRegistryList(HKEY hKey, CString &strValue, CStringArray &keyValue)
{
// HKEY hKey = GetConversionKey( "Data" );
DWORD dwType, dwCount;
long index = 0;
LONG lResult = 0;
CHAR ValueName[max_value];
DWORD dwcValueName = max_value;
CString data;
ValueName[0] = '\0';
dwCount = max_value;
lResult = RegEnumValue(hKey,index,ValueName,//regenumvalue return the key value names.
&dwcValueName, NULL, &dwType, NULL, &dwCount);
while(lResult != ERROR_NO_MORE_ITEMS)
{
RegQueryValueEx(hKey, ValueName, NULL, &dwType, (LPBYTE)data.GetBuffer(dwCount/sizeof(TCHAR)),
&dwCount);
data.ReleaseBuffer();
CString str = (CString)ValueName;
if(!(str.IsEmpty())) //neglecting the default value.
{
str = (CString)ValueName + "#" + data;
//concatenating the key value and its data
//separating with #
keyValue.Add((LPCTSTR)str);
}
++index;
dwcValueName = max_value;
lResult = RegEnumValue(hKey,index,ValueName, &dwcValueName,NULL,&dwType,NULL, &dwCount);
}
//this call is for default viewer.
lResult = RegQueryValueEx(hKey, NULL, NULL, &dwType, NULL, &dwCount);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
lResult = RegQueryValueEx(hKey, NULL, NULL, &dwType, (LPBYTE)strValue.GetBuffer(dwCount/sizeof(TCHAR)),
&dwCount);
strValue.ReleaseBuffer();
}
RegCloseKey(hKey);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
return TRUE;
}
return FALSE;
}
BOOL GetLeftRegistryList(HKEY hKey, CString &strValue, CStringArray &keyValue)
{
// HKEY hKey = GetConversionKey( "Data" );
DWORD dwType, dwCount;
long index = 0;
LONG lResult = 0;
CHAR ValueName[max_value];
DWORD dwcValueName = max_value;
CString data;
ValueName[0] = '\0';
dwCount = max_value;
lResult = RegEnumValue(hKey,index,ValueName,//regenumvalue return the key value names.
&dwcValueName, NULL, &dwType, NULL, &dwCount);
while(lResult != ERROR_NO_MORE_ITEMS)
{
RegQueryValueEx(hKey, ValueName, NULL, &dwType, (LPBYTE)data.GetBuffer(dwCount/sizeof(TCHAR)),
&dwCount);
data.ReleaseBuffer();
CString str = (CString)ValueName;
if(!(str.IsEmpty())) //neglecting the default value.
{
str = (CString)ValueName;
//concatenating the key value and its data
//separating with #
keyValue.Add((LPCTSTR)str);
}
++index;
dwcValueName = max_value;
lResult = RegEnumValue(hKey,index,ValueName, &dwcValueName, NULL, &dwType, NULL, &dwCount);
}
//this call is for default viewer.
lResult = RegQueryValueEx(hKey, NULL, NULL, &dwType, NULL, &dwCount);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
lResult = RegQueryValueEx(hKey, NULL, NULL, &dwType, (LPBYTE)strValue.GetBuffer(dwCount/sizeof(TCHAR)),
&dwCount);
strValue.ReleaseBuffer();
}
RegCloseKey(hKey);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
return TRUE;
}
return FALSE;
}
BOOL AddRegValue(const CString& key, const CString& value, const CString& data)
{
HKEY hKey = GetRegistryKey(key);
LPCTSTR lpszEntry = value;
LPCTSTR lpszValue = data;
if (hKey == NULL)
return FALSE;
LONG lResult = RegSetValueEx(hKey, lpszEntry, NULL, REG_SZ, (LPBYTE)lpszValue, (lstrlen(lpszValue)+1)*sizeof
TCHAR));
RegCloseKey(hKey);
//adding in the registry so that number of extensions can be retrieved
//for which the viewers are added.
SetKruseExtension(value, data);
if(lResult == ERROR_SUCCESS)
return TRUE;
else
return FALSE;
}
BOOL DeleteRegValue(const CString& key, const CString& value, const CString& data)
{
HKEY hKey = GetRegistryKey(key);
LPCTSTR lpszEntry = value;
LPCTSTR lpszValue = data;
if (hKey == NULL)
return FALSE;
LONG lResult = RegSetValueEx(hKey, lpszEntry, NULL, REG_SZ, (LPBYTE)lpszValue, (lstrlen(lpszValue)+1)*sizeof
TCHAR));
RegCloseKey(hKey);
//adding in the registry so that number of extensions can be retrieved
//for which the viewers are added.
SetKruseExtension(value , data);
if(lResult == ERROR_SUCCESS)
return TRUE;
else
return FALSE;
}
/* ************************************************************
Registry functions ENDS
************************************************************/

return 0;
}
AnswerRe: REGISTRY KEY: How to read/write Pin
ThatsAlok16-May-07 22:36
ThatsAlok16-May-07 22:36 
QuestionSelectively delete in multi column List Control Pin
ldsdbomber10-May-07 5:57
ldsdbomber10-May-07 5:57 
AnswerRe: Selectively delete in multi column List Control Pin
David Crow10-May-07 7:36
David Crow10-May-07 7:36 
AnswerRe: Selectively delete in multi column List Control Pin
Mark Salsbery10-May-07 7:38
Mark Salsbery10-May-07 7:38 
GeneralRe: Selectively delete in multi column List Control Pin
ldsdbomber11-Jun-07 3:08
ldsdbomber11-Jun-07 3:08 
GeneralRe: Selectively delete in multi column List Control Pin
ldsdbomber11-Jun-07 3:13
ldsdbomber11-Jun-07 3:13 
GeneralRe: Selectively delete in multi column List Control Pin
ldsdbomber11-Jun-07 3:14
ldsdbomber11-Jun-07 3:14 
GeneralRe: Selectively delete in multi column List Control Pin
Mark Salsbery11-Jun-07 6:43
Mark Salsbery11-Jun-07 6:43 
GeneralRe: Selectively delete in multi column List Control Pin
ldsdbomber11-Jun-07 23:05
ldsdbomber11-Jun-07 23:05 
GeneralRe: Selectively delete in multi column List Control Pin
Mark Salsbery12-Jun-07 6:46
Mark Salsbery12-Jun-07 6:46 
Questioncomparison between string and int Pin
prithaa10-May-07 5:07
prithaa10-May-07 5:07 
AnswerRe: comparison between string and int Pin
led mike10-May-07 5:18
led mike10-May-07 5:18 
AnswerRe: comparison between string and int Pin
David Crow10-May-07 5:54
David Crow10-May-07 5:54 
GeneralRe: comparison between string and int Pin
prithaa11-May-07 23:53
prithaa11-May-07 23:53 
AnswerRe: comparison between string and int Pin
Nelek13-May-07 20:07
protectorNelek13-May-07 20:07 
QuestionQuestion about fonts Pin
KellyR10-May-07 4:35
KellyR10-May-07 4:35 
AnswerRe: Question about fonts Pin
Mark Salsbery10-May-07 5:37
Mark Salsbery10-May-07 5:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.