Segmentation Fault

Hi,

Someone can help me to solve the problem with segmentation fault ?

This is code below, error apears on the line with RegQueryValueExW.
In debugger value is < Address 0x..... out of bounds>

CODE::BLOCK , WX GUI.

<code>
#define BUFFER 8192
HKEY key = 0;
wchar_t *value;
DWORD dwType = REG_SZ;
DWORD BufferSize = BUFFER;


if (RegOpenKeyExW( HKEY_CURRENT_USER,L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0, KEY_QUERY_VALUE,&key) == ERROR_SUCCESS )
{

RegQueryValueExW(key, L"AutoConfigURL", 0, &dwType, (LPBYTE)value, &BufferSize);

}

RegCloseKey( key );

</CODE>


Thanks in advance.

Regards,
grzybek
wchar_t *value;

This does not work. You need to allocate memory for *value

wchar_t *value = new wchar_t[BUFFER]

or better use a static buffer like.

wchar_t value[BUFFER];

Thomas, thanks a lot ! It works :)
At the beggining in almost empty project my code also worked (?)

Regards
At the beggining in almost empty project my code also appeared to worked (?)


One of the unfortunate things about undefined behavior is that it may appear to work the way one expects it to.
Topic archived. No new replies allowed.