|
12 | 12 |
|
13 | 13 | DBFHandle SHPAPI_CALL DBFOpen_MW( CStringW pszFilename, const char * pszAccess ) |
14 | 14 | { |
15 | | - CStringA nameA = Utility::ConvertToAnsi1252(pszFilename); |
| 15 | + CStringA nameA = Utility::ConvertToUtf8(pszFilename); |
| 16 | + |
| 17 | + // Save current locale, then switch CRT to UTF-8 so fopen() inside DBFOpen |
| 18 | + // interprets the path bytes as UTF-8 instead of the system ANSI code page. |
| 19 | + // Requires Windows 10 1803 or later. |
| 20 | + CStringA prevLocale = setlocale(LC_ALL, nullptr); |
| 21 | + setlocale(LC_ALL, ".UTF8"); |
| 22 | + |
16 | 23 | m_globalSettings.SetGdalUtf8(true); |
17 | 24 | DBFHandle handle = DBFOpen(nameA, pszAccess); |
18 | 25 | m_globalSettings.SetGdalUtf8(false); |
| 26 | + |
| 27 | + // Restore previous locale |
| 28 | + setlocale(LC_ALL, prevLocale); |
| 29 | + |
19 | 30 | return handle; |
20 | 31 | } |
21 | 32 |
|
22 | 33 | DBFHandle SHPAPI_CALL DBFCreate_MW( CStringW nameW ) |
23 | 34 | { |
24 | | - CStringA nameA = Utility::ConvertToAnsi1252(nameW); |
| 35 | + CStringA nameA = Utility::ConvertToUtf8(nameW); |
| 36 | + |
| 37 | + // Save current locale, then switch CRT to UTF-8 so fopen() inside DBFCreate |
| 38 | + // interprets the path bytes as UTF-8 instead of the system ANSI code page. |
| 39 | + // Requires Windows 10 1803 or later. |
| 40 | + CStringA prevLocale = setlocale(LC_ALL, nullptr); |
| 41 | + setlocale(LC_ALL, ".UTF8"); |
| 42 | + |
25 | 43 | m_globalSettings.SetGdalUtf8(true); |
26 | 44 | DBFHandle handle = DBFCreate(nameA); |
27 | 45 | m_globalSettings.SetGdalUtf8(false); |
| 46 | + |
| 47 | + // Restore previous locale |
| 48 | + setlocale(LC_ALL, prevLocale); |
| 49 | + |
28 | 50 | return handle; |
29 | 51 | } |
30 | 52 |
|
|
0 commit comments