Jump to content
  • Advertisement
Sign in to follow this  
valleyman86

ini file failing?

This topic is 4700 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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.

Share this post


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

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!