@@ -64,21 +64,39 @@ bool ffRegReadStrbuf(HKEY hKey, const wchar_t* valueNameW, FFstrbuf* result, FFs
6464 return true;
6565}
6666
67- bool ffRegReadData (HKEY hKey , const wchar_t * valueNameW , uint8_t * result , uint32_t bufSize , FFstrbuf * error )
67+ bool ffRegReadData (HKEY hKey , const wchar_t * valueNameW , uint8_t * * result , uint32_t * length , FFstrbuf * error )
6868{
69- static_assert (sizeof (DWORD ) == sizeof (uint32_t ), "" );
70- LONG err = RegGetValueW (hKey , NULL , valueNameW , RRF_RT_REG_BINARY , NULL , result , (DWORD * ) & bufSize );
69+ assert (result && length );
70+ DWORD bufSize = 0 ;
71+ LONG err = RegGetValueW (hKey , NULL , valueNameW , RRF_RT_REG_BINARY , NULL , NULL , & bufSize );
72+ if (err != ERROR_SUCCESS || bufSize == 0 )
73+ {
74+ if (error )
75+ {
76+ if (!valueNameW )
77+ valueNameW = L"(default)" ;
78+ FF_STRBUF_AUTO_DESTROY valueNameA = ffStrbufCreateWS (valueNameW );
79+ ffStrbufAppendF (error , "RegGetValueW(%s, NULL, RRF_RT_REG_BINARY, NULL, NULL, &bufSize) failed" , valueNameA .chars );
80+ }
81+ return false;
82+ }
83+
84+ uint8_t * buf = (uint8_t * ) malloc (bufSize );
85+ err = RegGetValueW (hKey , NULL , valueNameW , RRF_RT_REG_BINARY , NULL , buf , & bufSize );
7186 if (err != ERROR_SUCCESS )
7287 {
7388 if (error )
7489 {
7590 if (!valueNameW )
7691 valueNameW = L"(default)" ;
7792 FF_STRBUF_AUTO_DESTROY valueNameA = ffStrbufCreateWS (valueNameW );
78- ffStrbufAppendF (error , "RegGetValueW(%s, NULL, RRF_RT_REG_SZ ) failed" , valueNameA .chars );
93+ ffStrbufAppendF (error , "RegGetValueW(%s, NULL, RRF_RT_REG_BINARY, NULL, length ) failed" , valueNameA .chars );
7994 }
95+ free (buf );
8096 return false;
8197 }
98+ * result = buf ;
99+ * length = bufSize ;
82100 return true;
83101}
84102
0 commit comments