ini file failing?

Started by
2 comments, last by valleyman86 18 years, 5 months ago
Ok it will write the ini file if I do not put anything into the edit box im getting text from. when I do it fails yet the message box displays wat is in the array correctly. Once it fails it wont work again til I recompile the app completly. Closing and reopening dont work.
				case(BUTTON_SUBMIT_ID):
					{
						if (GetDlgItem(hWnd, BUTTON_SUBMIT_ID)) {
							HWND tab = GetDlgItem(hWnd, 0);
							char test[256];

							HWND item = GetDlgItem(tab, EDIT_CAP_LOC_ID);
							int length = SendMessage(item, WM_GETTEXTLENGTH, NULL, NULL);
							SendMessage(item, WM_GETTEXT, length+1, (LPARAM)test);
							if (!WritePrivateProfileString("Settings", "CaptureDir", test, ".\\Release\\save.cfg")) {
								MessageBox(NULL, test, "failed", MB_OK);
							}

							item = GetDlgItem(tab, HOTKEY_SCREEN_ID);
							length = SendMessage(item, WM_GETTEXTLENGTH, NULL, NULL);
							SendMessage(item, WM_GETTEXT, length+1, (LPARAM)test);
							if (!WritePrivateProfileString("Settings", "ScreenshotHotkey", test, ".\\Release\\save.cfg")) {
								MessageBox(NULL, "failed2", "failed", MB_OK);
							}
							

							item = GetDlgItem(tab, HOTKEY_VIDEO_ID);
							length = SendMessage(item, WM_GETTEXTLENGTH, NULL, NULL);
							SendMessage(item, WM_GETTEXT, length+1, (LPARAM)test);
							if (!WritePrivateProfileString("Settings", "VideoHotkey", test, ".\\Release\\save.cfg")) {
								MessageBox(NULL, "failed3", "failed", MB_OK);
							}

							item = GetDlgItem(tab, COMBO_RESOLUTION_ID);
							length = SendMessage(item, WM_GETTEXTLENGTH, NULL, NULL);
							SendMessage(item, WM_GETTEXT, length+1, (LPARAM)test);
							if (!WritePrivateProfileString("Settings", "Resolution", test, ".\\Release\\save.cfg")) {
								MessageBox(NULL, "failed4", "failed", MB_OK);
							}
						}	
					}
					break;
-------------------------------------------
http://www.MurderDev.com - Developing Killer Software
http://www.MobileCellOut.com - Cell Phone Contract Exchange
Advertisement
Quote:Original post by valleyman86
Ok it will write the ini file if I do not put anything into the edit box im getting text from. when I do it fails yet the message box displays wat is in the array correctly. Once it fails it wont work again til I recompile the app completly. Closing and reopening dont work.
Why not use GetWindowTextLength and GetWindowText instead of explicitly using SendMessage?
Also, if the text is longer than 256 bytes then it will cause a buffer overflow. You'd be better off to allocate 'test' using alloca, or something like that. Or you could use EM_LIMITTEXT instead I suppose.

Try calling GetLastError() when WritePrivateProfileString fails and see what the error code is.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
hmm well I tried the error code thing. Ether it kept crashing trying to make the code readable or it would just print some weird stuff so i said screw it.
-------------------------------------------
http://www.MurderDev.com - Developing Killer Software
http://www.MobileCellOut.com - Cell Phone Contract Exchange
alright just tested and still same error now sure why. Hmm and could some show me how to get the proper error code even if I have too look it up. I keep getting some error. Dont link me to the example on msdn I read it and it confused me.
-------------------------------------------
http://www.MurderDev.com - Developing Killer Software
http://www.MobileCellOut.com - Cell Phone Contract Exchange

This topic is closed to new replies.

Advertisement