Boxedwine icon indicating copy to clipboard operation
Boxedwine copied to clipboard

`GetPrivateProfileString(W?)` issues

Open nikvoid opened this issue 9 months ago • 2 comments

GetPrivateProfileStringW result differs on real pc and boxedwine. INI file:

[]
down=Down

Test program:

#define UNICODE
#define _UNICODE
#include <windows.h>
#include <stdio.h>

int wmain(int argc, wchar_t *argv[]) {
    LPCWSTR ini = L"file.ini";
    LPCWSTR section = L"";       // Section name
    LPCWSTR key = L"down";       // Key name
    LPCWSTR defaultValue = L"";  // Default value if key not found

    WCHAR iniFile[MAX_PATH];  // Use MAX_PATH instead
    
    if (GetFullPathNameW(ini, MAX_PATH, iniFile, NULL) == 0) {
        wprintf(L"Error: could not get full path to ini file, Error: %d\n", GetLastError());
        return 1;
    } 
    
    wprintf(L"Full path: `%s`\n", iniFile);

    // Buffer to store the retrieved value
    WCHAR buffer[256];
    DWORD result;

    // Check if INI file exists
    HANDLE hFile = CreateFileW(iniFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile == INVALID_HANDLE_VALUE) {
        wprintf(L"Error: Could not open INI file. Error code: %d\n", GetLastError());
        return 1;
    }
    CloseHandle(hFile);

    // Retrieve the value using GetPrivateProfileStringW
    result = GetPrivateProfileStringW(section, key, defaultValue, buffer, 
                                     sizeof(buffer) / sizeof(WCHAR), iniFile);

    // Check if a value was retrieved
    if (result == 0) {
        wprintf(L"Key '%s' in section '%s' not found or empty\n", key, section);
    } else {
        wprintf(L"Value for '%s' in section '%s': %s\n", key, section, buffer);
    }

    return 0;
}

Output on real pc:

Full path: `D:\project\werdia\dist\Win64\check\file.ini`
Value for 'down' in section '': Down

Boxedwine:

Full path: `C:\files\file.ini`
Key 'down' section '' not found or empty

+relay,-debug log:

0009:Call KERNEL32.GetFullPathNameW(0041b000 L"file.ini",00000104,0032fc5c,00000000) ret=00401056
0009:Ret  KERNEL32.GetFullPathNameW() retval=00000011 ret=00401056
0009:Call ntdll.RtlAllocateHeap(00110000,00000000,00001000) ret=004085a1
0009:Ret  ntdll.RtlAllocateHeap() retval=0011c2f8 ret=004085a1
0009:Call KERNEL32.WriteFile(00000017,0032dfe4,00000020,0032dfe0,00000000) ret=0040d160
Full path: `C:\files\file.ini`
0009:Ret  KERNEL32.WriteFile() retval=00000001 ret=0040d160
0009:Call KERNEL32.CreateFileW(0032fc5c L"C:\\files\\file.ini",80000000,00000001,00000000,00000003,00000080,00000000) ret=004010ab
0009:Ret  KERNEL32.CreateFileW() retval=00000020 ret=004010ab
0009:Call KERNEL32.CloseHandle(00000020) ret=004010e5
0009:Ret  KERNEL32.CloseHandle() retval=00000001 ret=004010e5
0009:Call KERNEL32.GetPrivateProfileStringW(0041bac8 L"",0041b014 L"down",0041bacc L"",0032fa5c,00000100,0032fc5c L"C:\\files\\file.ini") ret=00401113
0009:Ret  KERNEL32.GetPrivateProfileStringW() retval=00000000 ret=00401113
0009:Call KERNEL32.WriteFile(00000017,0032dfe0,0000002d,0032dfdc,00000000) ret=0040d160
Key 'down' in section '' not found or empty
0009:Ret  KERNEL32.WriteFile() retval=00000001 ret=0040d160

P.S. Is this actually a wine issue?

nikvoid avatar Apr 21 '25 13:04 nikvoid