Click here to Skip to main content
15,889,767 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Sanity Check on Registry Value REG_MULTI_SZ - format value Pin
jkirkerx27-Oct-11 11:48
professionaljkirkerx27-Oct-11 11:48 
GeneralRe: Sanity Check on Registry Value REG_MULTI_SZ - format value Pin
jkirkerx27-Oct-11 13:28
professionaljkirkerx27-Oct-11 13:28 
AnswerRe: Sanity Check on Registry Value REG_MULTI_SZ - format value Pin
Peter_in_278027-Oct-11 13:39
professionalPeter_in_278027-Oct-11 13:39 
GeneralRe: Sanity Check on Registry Value REG_MULTI_SZ - format value Pin
jkirkerx28-Oct-11 6:24
professionaljkirkerx28-Oct-11 6:24 
AnswerRe: Sanity Check on Registry Value REG_MULTI_SZ - format value Pin
Richard MacCutchan27-Oct-11 21:59
mveRichard MacCutchan27-Oct-11 21:59 
GeneralRe: Sanity Check on Registry Value REG_MULTI_SZ - format value Pin
jkirkerx28-Oct-11 6:41
professionaljkirkerx28-Oct-11 6:41 
GeneralRe: Sanity Check on Registry Value REG_MULTI_SZ - format value Pin
Richard MacCutchan28-Oct-11 6:57
mveRichard MacCutchan28-Oct-11 6:57 
GeneralRe: Sanity Check on Registry Value REG_MULTI_SZ - format value Pin
jkirkerx28-Oct-11 7:17
professionaljkirkerx28-Oct-11 7:17 
That's the mistake from yesterday I posted in full.

Today I will fix the 2 registry programs, I was thinking wchar_t, but I'll go with WCHAR.

The following registry function , is ran after the one I posted above, so you can get an idea of what I'm doing. I wrote the char stuff by myself, with no help, hope it passes. I started changing the code to wchar so I know the code doesn't work, it's just foresight.

I run the first program, return the values and seperate the names, and then loop through the names with the program below to get the versions

wchar_t* CA_Registry::_get_SQLServer_Version( const wchar_t *szSQLInstance )
{
	HKEY keyHandle;
	
	char rgValue [1024];
	char szVersion[1024];

	// Declare the Prefix and Suffix of the Reg Key
	char szRegPath[125];
	char *szRegPath_Prefix = "SOFTWARE\\Microsoft\\Microsoft SQL Server\\";
	char *szRegPath_Suffix = "\\MSSQLServer\\CurrentVersion\\";

	// Calculate the String Lengths
	int iRegPath_Prefix = strlen(szRegPath_Prefix);
	//int iRegPath_Instance = strlen(szSQLInstance);
	int iRegPath_Suffix = strlen(szRegPath_Suffix);
	
	//Build the Char Arrays
	strncpy_s(szRegPath, _countof(szRegPath), szRegPath_Prefix, iRegPath_Prefix);
	//strncat_s(szRegPath, _countof(szRegPath), szSQLInstance, iRegPath_Instance);
	strncat_s(szRegPath, _countof(szRegPath), szRegPath_Suffix, iRegPath_Suffix);
	
	// Convert the Char Arrays to Wide String
	int buffSize = (int)strlen(szRegPath) + 1;
	LPWSTR lpRegPath = new wchar_t[buffSize];
	MultiByteToWideChar(CP_ACP, 0, szRegPath, buffSize, lpRegPath, buffSize);
	
	LPWSTR lpRegReq = L"CurrentVersion";
		
	DWORD size1 = sizeof(rgValue);
	DWORD Type;
	DWORD dwType = 0;
	DWORD regStatus = REG_SZ;

	int ndx=0;
	int szRgVal;
	int maxStr;	
			
	if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRegPath, 0, KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS) {
		
		dwType = REG_SZ;
		regStatus = RegQueryValueEx( keyHandle, lpRegReq, NULL, &Type, (LPBYTE)rgValue,&size1);
			
		switch ( regStatus ) {
			case ERROR_SUCCESS:
				ndx=0;
				szRgVal=sizeof(rgValue);
	
				for(int i=0;i<szRgVal;i++) {
					szVersion[ndx++]=rgValue[i];
					i++;
				}
	
				maxStr=strlen(szVersion);	
				szVersion[maxStr-0]=(char)'\0';
				printf(" Binary path: %s %i\n", szVersion, strlen(szVersion) );				
								
				RegCloseKey(keyHandle);
				cout << "key was read successfully\n";
				break;

			case ERROR_MORE_DATA:
				cout << "Buffer too small\n";
				break;			

			default:			
				cout << "Count not read key\n";
		}
	}
	else {
		cout << "Can not open key";
		cin.ignore();
	}

	// Free the Memory
	delete [] lpRegPath;

	int strLength = strlen(szVersion);
	wchar_t *szReturnValue = new wchar_t[strLength];
	for (int i = 0; i < strLength; i++) {
		szReturnValue[i] = szVersion[i];
	}
	szReturnValue[ strLength ] = '\0';	
	return szReturnValue;

	delete [] szReturnValue;	
}

AnswerI rewrote the my function for WCHAR Pin
jkirkerx28-Oct-11 8:22
professionaljkirkerx28-Oct-11 8:22 
AnswerRe: I rewrote the my function for WCHAR Pin
Richard MacCutchan28-Oct-11 23:13
mveRichard MacCutchan28-Oct-11 23:13 
GeneralRe: I rewrote the my function for WCHAR Pin
jkirkerx29-Oct-11 7:39
professionaljkirkerx29-Oct-11 7:39 
GeneralRe: I rewrote the my function for WCHAR Pin
jkirkerx29-Oct-11 8:20
professionaljkirkerx29-Oct-11 8:20 
GeneralRe: I rewrote the my function for WCHAR Pin
Richard MacCutchan29-Oct-11 22:21
mveRichard MacCutchan29-Oct-11 22:21 
GeneralRe: I rewrote the my function for WCHAR Pin
jkirkerx30-Oct-11 6:32
professionaljkirkerx30-Oct-11 6:32 
GeneralRe: I rewrote the my function for WCHAR Pin
Richard MacCutchan30-Oct-11 7:16
mveRichard MacCutchan30-Oct-11 7:16 
GeneralRe: I rewrote the my function for WCHAR - grovel Pin
Richard MacCutchan29-Oct-11 23:19
mveRichard MacCutchan29-Oct-11 23:19 
QuestionRegistry usage in MFC Doc/ View - opinions / commentary wanted Pin
Vaclav_27-Oct-11 5:18
Vaclav_27-Oct-11 5:18 
AnswerRe: Registry usage in MFC Doc/ View - opinions / commentary wanted Pin
Albert Holguin27-Oct-11 5:35
professionalAlbert Holguin27-Oct-11 5:35 
Questionfopen crashed when special characters found. Pin
tagopi27-Oct-11 2:12
tagopi27-Oct-11 2:12 
AnswerRe: fopen crashed when special characters found. Pin
Luc Pattyn27-Oct-11 2:53
sitebuilderLuc Pattyn27-Oct-11 2:53 
AnswerRe: fopen crashed when special characters found. Pin
Chris Losinger27-Oct-11 3:22
professionalChris Losinger27-Oct-11 3:22 
AnswerRe: fopen crashed when special characters found. Pin
David Crow27-Oct-11 4:49
David Crow27-Oct-11 4:49 
AnswerRe: fopen crashed when special characters found. Pin
Andrew Brock27-Oct-11 7:43
Andrew Brock27-Oct-11 7:43 
GeneralRe: fopen crashed when special characters found. Pin
jschell27-Oct-11 8:30
jschell27-Oct-11 8:30 
GeneralRe: fopen crashed when special characters found. Pin
Andrew Brock27-Oct-11 8:36
Andrew Brock27-Oct-11 8:36 

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.