Sign in to follow this  
valleyman86

ini file failing?

Recommended Posts

valleyman86    126
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;

Share this post


Link to post
Share on other sites
iMalc    2466
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.

Share this post


Link to post
Share on other sites
valleyman86    126
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this