Changeset 208 in Main for trunk/Server/main.c


Ignore:
Timestamp:
Oct 2, 2024, 11:59:59 AM (6 weeks ago)
Author:
Nishi
Message:

do this instead

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Server/main.c

    r206 r208  
    7474#ifdef __MINGW32__
    7575char* get_registry(const char* main, const char* sub) {
    76         DWORD bufsize = 255;
    77         char* value = malloc(256);
    78         int err = RegGetValue(HKEY_LOCAL_MACHINE, main, sub, RRF_RT_ANY, NULL, (void*)value, &bufsize);
     76        DWORD bufsize = 512;
     77        HKEY handle;
     78        char* value = malloc(513);
     79        int err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, main, 0, KEY_QUERY_VALUE, &handle);
    7980        if(err == ERROR_SUCCESS) {
     81                err = RegQueryValueEx(handle, sub, NULL, NULL, value, &bufsize);
     82                if(err != ERROR_SUCCESS) {
     83                        free(value);
     84                        RegCloseKey(handle);
     85                        return NULL;
     86                }
     87                RegCloseKey(handle);
    8088                return value;
    8189        } else {
     
    503511
    504512int main(int argc, char** argv) {
     513        printf("%s\n", get_registry("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Tewi HTTPd", "InstallDir"));
    505514        logfile = stderr;
    506515#ifdef SERVICE
Note: See TracChangeset for help on using the changeset viewer.