Helo I am having problems with reading/writing to registry.. Apparently it saves the string values correctly every time, but after i changed them (from within the program), and i open the dialog box again to see the values, it fails to read from registry. WHen i restart the program and open the dialog box, then it reads the values in correctly... Anyone of you folks have any experience with this see whats wrong? --thanks regards, SeeDee

...
.data
	bufferlen	dd	MAX_BUFSIZE
	szRegPath	db	"Software\MyIRC", 0
	szServer	db	"Server", 0
	szPassword	db	"Password", 0
	szPort		db	"Port", 0

.data?
	buffer2		db		MAX_BUFSIZE dup(?)

;#########################################################

SettingsDlgProc	PROC	hDlg:DWORD, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
	.IF	uMsg == WM_INITDIALOG
		invoke	SendDlgItemMessage, hDlg, IDC_PORT, EM_SETLIMITTEXT, 5, 0

		invoke	RegOpenKeyEx, HKEY_LOCAL_MACHINE, addr szRegPath, 0, KEY_READ, addr temp1
		.IF (eax == ERROR_SUCCESS)

			invoke	RtlZeroMemory, addr buffer2, sizeof buffer2
			invoke	RegQueryValueEx, temp1, addr szServer, 0, addr temp2, addr buffer2, addr bufferlen
			.IF (eax == ERROR_SUCCESS)
				invoke	SetDlgItemText, hDlg, IDC_SERVER, addr buffer2
			.ENDIF

			invoke	RtlZeroMemory, addr buffer2, sizeof buffer2
			invoke	RegQueryValueEx, temp1, addr szPassword, 0, addr temp2, addr buffer2, addr bufferlen
			.IF (eax == ERROR_SUCCESS)
				invoke	SetDlgItemText, hDlg, IDC_PASSWORD, addr buffer2
			.ENDIF

			invoke	RtlZeroMemory, addr buffer2, sizeof buffer2
			invoke	RegQueryValueEx, temp1, addr szPort, 0, addr temp2, addr buffer2, addr bufferlen
			.IF (eax == ERROR_SUCCESS)
				invoke	SetDlgItemText, hDlg, IDC_PORT, addr buffer2
			.ENDIF

			invoke	RegCloseKey, temp1
		.ENDIF

	.ELSEIF	uMsg == WM_COMMAND
		mov	eax, wParam
		.IF	ax == IDC_OK
			invoke	GetDlgItemText, hDlg, IDC_SERVER, addr buffer2, sizeof buffer2
			invoke	RegSaveString, HKEY_LOCAL_MACHINE, addr szRegPath, addr szServer, addr buffer2

			invoke	GetDlgItemText, hDlg, IDC_PASSWORD, addr buffer2, sizeof buffer2
			invoke	RegSaveString, HKEY_LOCAL_MACHINE, addr szRegPath, addr szPassword, addr buffer2

			invoke	GetDlgItemText, hDlg, IDC_PORT, addr buffer2, sizeof buffer2
			invoke	RegSaveString, HKEY_LOCAL_MACHINE, addr szRegPath, addr szPort, addr buffer2

			invoke	SendMessage, hDlg, WM_CLOSE, 0, 0
			invoke	inet_addr, addr buffer
			mov	serverip, eax
		.ELSEIF	ax == IDC_CANCEL
			invoke	SendMessage, hDlg, WM_CLOSE, 0, 0
		.ENDIF

	.ELSEIF	uMsg == WM_CLOSE
		invoke	EndDialog, hDlg, 0
	.ELSE
		xor	eax, eax
		ret
	.ENDIF

	mov	eax, TRUE
	ret
SettingsDlgProc	ENDP


RegSaveString	PROC	hKey:DWORD, sPath:LPSTR, sValue:LPSTR, sData:LPSTR
	LOCAL	keyhand:DWORD

	invoke	RegCreateKey, hKey, sPath, ADDR keyhand
	invoke	lstrlen, sData
	invoke	RegSetValueEx, keyhand, sValue, 0, REG_SZ, sData, eax
	invoke	RegCloseKey, keyhand
	ret
RegSaveString	ENDP

Posted on 2001-06-16 05:45:00 by SeeDee
Hi there, I tried Registry for the first time two days ago (in my first own program:confused: ) so I don't know if its of any help but perhaps you need KEY_QUERY_VALUE on RegKeyOpen in addition to KEY_READ. I tried it myself before but actually I had help from a snake game program I downloaded here http://www.alloces.cjb.net/. It uses RegCreateKeyEx instead of RegKeyOpen so if nothing helps you might wanna take a look at it. This message was edited by goofee, on 6/16/2001 12:26:19 PM
Posted on 2001-06-16 12:22:00 by goofee