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;
ini file failing?
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.
Quote:Original post by valleyman86Why not use GetWindowTextLength and GetWindowText instead of explicitly using SendMessage?
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement