Click here to Skip to main content
15,890,690 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Stupid CBitmapButton question regarding resource editor. Pin
led mike20-Jun-06 8:53
led mike20-Jun-06 8:53 
QuestionRe: Stupid CBitmapButton question regarding resource editor. Pin
David Crow20-Jun-06 9:32
David Crow20-Jun-06 9:32 
AnswerRe: Stupid CBitmapButton question regarding resource editor. Pin
Maximilien20-Jun-06 10:11
Maximilien20-Jun-06 10:11 
GeneralRe: Stupid CBitmapButton question regarding resource editor. Pin
David Crow20-Jun-06 10:27
David Crow20-Jun-06 10:27 
QuestionKNOX Forum Pin
knoxplusplus20-Jun-06 7:37
knoxplusplus20-Jun-06 7:37 
AnswerRe: KNOX Forum Pin
David Crow20-Jun-06 7:41
David Crow20-Jun-06 7:41 
AnswerRe: KNOX Forum Pin
toxcct20-Jun-06 21:36
toxcct20-Jun-06 21:36 
QuestionIssues with pointers [modified] Pin
capricious_00120-Jun-06 6:46
capricious_00120-Jun-06 6:46 
Hi there,

I am basically having trouble acquiring the pointed value of a pointer. Below is the code I am working with.

<code>

//--- main start ---

int main( void ){

	char* RegLocation = "";


	char rspath[255];
	strcpy(rspath,"");

	
	if(GetRegistryValue(HKEY_LOCAL_MACHINE,"SOFTWARE\\Red Storm Entertainment\\Rogue Spear","InstallationPath",rspath)){
		
		lstrcat(rspath, "\\");
		lstrcpy(RegLocation, rspath);
	
		if(retrieveLogFileLocation(RegLocation)){
			
			if(GenerateStats(RegLocation, hOutput)){
				//Continue on
			}
		}
	}
	

	return 0;
}



BOOL GetRegistryValue(HKEY key, const char* path, const char* name, char* value)
{
	HKEY hKey;

	strcpy(value,"");
	if (RegOpenKeyEx(key, path, 0, KEY_EXECUTE, &hKey) == ERROR_SUCCESS)
	{
		char szBuf[MAX_PATH];
		DWORD dwLen=MAX_PATH;
		
		if (RegQueryValueEx(hKey, name, NULL, NULL, (unsigned char*) szBuf, &dwLen) == ERROR_SUCCESS)
		{
			strcpy(value,szBuf);
			RegCloseKey(hKey);
			return TRUE;
		}

		RegCloseKey(hKey);		
		hKey = NULL;
	}

	return FALSE;
}

bool retrieveLogFileLocation(LPSTR lszRSPath){
	char lszValue[255];
	char search[255];
	
	
	lstrcpy(search,lszRSPath);
	lstrcpy(lszValue,lszRSPath);
	lstrcat(search, "*.log");

	WIN32_FIND_DATA wfd;
	HANDLE hFind = FindFirstFile(search, &wfd);	

	
	if (hFind != INVALID_HANDLE_VALUE) {
		do 
		{	
			string foo = wfd.cFileName;			
			
			if (foo.find("RSResults") != -1)
			{		

				lstrcat(lszValue,wfd.cFileName);
				lstrcpy(lszRSPath, lszValue);

				FindClose(&wfd);
				return TRUE;		
			}
		} while (FindNextFile(hFind, &wfd));
		FindClose(&wfd);
	}

	return FALSE;

}

bool GenerateStats(LPSTR lszLogFile){

	HANDLE hLogFile = NULL;
	bool pSuccess = FALSE;

	
	cout << "Value pointed is " << lszLogFile << endl;
        cout << "Value dereferenced is " << *lszLogFile << endl;

	//Open log file
	hLogFile = CreateFile(lszLogFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
	
	if(hLogFile != INVALID_HANDLE_VALUE){
		cout << "Able to create file" << endl;
		//Lock log file
		DWORD dwFileSize, dwRead;
		dwFileSize = GetFileSize(hLogFile, NULL);

		if(LockFile(hLogFile, 0, 0, dwFileSize, 0))
		{			
			
			
			HANDLE hHeapFile;
			LPVOID lpvHeapFile;
				
			//Create File Heap
			hHeapFile = HeapCreate(0x00040000, dwFileSize, 0);
			

			if((DWORD)hHeapFile != STATUS_NO_MEMORY)
			{					
				
				lpvHeapFile = HeapAlloc(hHeapFile, HEAP_ZERO_MEMORY, 0);
				

				//Parse Log File Function
				if(parseLogFile(hLogFile, lpvHeapFile, dwFileSize, dwRead)){
						pSuccess = TRUE;	
				}
					
				//Destroy File Heap
				HeapDestroy(hHeapFile);
			}

		}
		UnlockFile(hLogFile, 0, 0, dwRead, 0);
		CloseHandle(hLogFile);
	}
	return pSuccess;
}


</code



My issue is that in the function definition GenerateStats outputting lszLogFile outputs the correct file path, so the value lszLogFile is pointing to is correct, however if I dereference the pointer, I get a value of c which is incorrect. c is what is passed onto the function CreateFile which is incorrect. I actually want the value that is referenced by lszLogFile to be passed onto that function.

I have tried multiple ways on passing on the pointed value with no success. I have tried to type-cast it in multiple ways such as: LPSTR, LPCSTR, const char* as well as changing the function parameter type of lszLogFile in the GenerateStats parameter list to different types. I have also tried copying the value of lszLogFile using lstrcpy() to another variable (as well as trying to static_cast the variables to various types) and it still does not work. Everytime I try to use lstrcpy() and I attempt to type cast say in the form of something like this:

LPSTR lpcsLogFile;

lstrcpy(lpcsLogFile, lszLogFile);

//or this

lstrcpy(lpcsLogFile, static_cast<const char*>(lszLogFile));


I receive unhandled exception errors (which I do understand why it happens but i've exausted all my know how in order to solve the problem!).

So if anyone can see where I am making my mistake, I would really appreciate any input.

Thanks!

Robbie


-- modified at 12:46 Tuesday 20th June, 2006

Made some grammatical changes!
AnswerRe: Issues with pointers Pin
Justin Tay20-Jun-06 7:11
Justin Tay20-Jun-06 7:11 
AnswerRe: Issues with pointers Pin
David Crow20-Jun-06 7:38
David Crow20-Jun-06 7:38 
GeneralRe: Issues with pointers [modified] Pin
capricious_00120-Jun-06 8:11
capricious_00120-Jun-06 8:11 
GeneralRe: Issues with pointers Pin
Justin Tay20-Jun-06 8:36
Justin Tay20-Jun-06 8:36 
GeneralRe: Issues with pointers Pin
capricious_00120-Jun-06 15:32
capricious_00120-Jun-06 15:32 
QuestionFTP server communication i n C++ Pin
LCI20-Jun-06 6:46
LCI20-Jun-06 6:46 
AnswerRe: FTP server communication i n C++ Pin
valikac20-Jun-06 8:20
valikac20-Jun-06 8:20 
GeneralRe: FTP server communication i n C++ Pin
LCI20-Jun-06 8:30
LCI20-Jun-06 8:30 
AnswerRe: FTP server communication i n C++ Pin
led mike20-Jun-06 9:38
led mike20-Jun-06 9:38 
GeneralRe: FTP server communication i n C++ Pin
LCI20-Jun-06 10:58
LCI20-Jun-06 10:58 
GeneralRe: FTP server communication i n C++ Pin
led mike20-Jun-06 11:55
led mike20-Jun-06 11:55 
GeneralRe: FTP server communication i n C++ Pin
LCI21-Jun-06 3:32
LCI21-Jun-06 3:32 
GeneralRe: FTP server communication i n C++ Pin
led mike21-Jun-06 5:02
led mike21-Jun-06 5:02 
QuestionGetting IP address of Network card Pin
act_x20-Jun-06 5:56
act_x20-Jun-06 5:56 
AnswerRe: Getting IP address of Network card Pin
David Crow20-Jun-06 6:12
David Crow20-Jun-06 6:12 
QuestionErrors: MSVC 6.0, SDI MFC APP. Pin
tingu20-Jun-06 5:37
tingu20-Jun-06 5:37 
QuestionRe: Errors: MSVC 6.0, SDI MFC APP. Pin
David Crow20-Jun-06 6:23
David Crow20-Jun-06 6:23 

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.