Udostępnij za pośrednictwem


_configthreadlocale

Konfiguruje opcje ustawień regionalnych dla wątku.

int _configthreadlocale(
   int type
);

Parametry

  • type
    Możliwość ustawienia.Jedną z opcji wymienionych w poniższej tabeli.

Wartość zwracana

Poprzedni stan ustawień regionalnych dla wątku (_DISABLE_PER_THREAD_LOCALE lub _ENABLE_PER_THREAD_LOCALE), lub -1 w przypadku awarii.

Uwagi

_configurethreadlocale Funkcja jest używana do kontrolowania wykorzystania ustawień regionalnych właściwych dla wątku.Można okreolić lub ustalić stan ustawień regionalnych dla wątku, należy użyć jednej z poniższych opcji:

  • _ENABLE_PER_THREAD_LOCALE
    Należy zgodnie z ustawieniami lokalnymi wykorzystania specyficznych wątek wątek.Kolejne wywołania setlocale w tym wątku wpływa na tylko ustawień regionalnych dla wątku.

  • _DISABLE_PER_THREAD_LOCALE
    Należy bieżącego wątku, użyj globalnego ustawienia regionalne.Kolejne wywołania setlocale w tym wątku wpływa na inne wątki za pomocą globalnych ustawień regionalnych.

  • 0
    Pobiera bieżące ustawienie tym wątku.

These functions affect the behavior of setlocale, _tsetlocale, _wsetlocale, _beginthread, and _beginthreadex.Jeśli inna metoda jest używany do tworzenia wątków, ustawienia regionalne nie mają wpływu na tych wątków.

Gdy ustawienia regionalne dla wątku jest wyłączona, wszelkie następne wywołanie setlocale lub _wsetlocale zmienia ustawienia regionalne wszystkie wątki.Po włączeniu ustawień regionalnych dla wątku, setlocale lub _wsetlocale dotyczy tylko bieżącego wątek.

Klienci korzystający z _configurethreadlocale Aby włączyć ustawienia regionalne dla wątku, zaleca się, że wywołania setlocale lub _wsetlocale zaraz potem ustawić preferowaną lokalizację w tym wątku.

Jeśli type nie jest jedną z wartości wymienionych w tabeli, funkcja ta wywołuje program obsługi nieprawidłowy parametr, z zgodnie z opisem w Sprawdzanie poprawności parametru.Jeśli wykonanie może kontynuować, ta funkcja ustawia errno do EINVAL i zwraca wartość -1.

Wymagania

Rozpoczęto wykonywanie procedury

Wymaganego nagłówka

_configthreadlocale

<locale.h>

Przykład

// crt_configthreadlocale.cpp
// 
// This program demonstrates the use of _configthreadlocale when
// using is two independent threads.
//

#include <locale.h>
#include <process.h>
#include <windows.h>
#include <stdio.h>
#include <time.h>

#define BUFF_SIZE 100

// Retrieve the date and time in the current
// locale's format.
int get_time(unsigned char* str)
{
    __time64_t  ltime;
    struct tm   thetime;

    // Retieve the time
    _time64(&ltime);
    _gmtime64_s(&thetime, &ltime);

    // Format the current time structure into a string
    // using %#x is the long date representation,
    // appropriate to the current locale
    if (!strftime((char *)str, BUFF_SIZE, "%#x", 
                  (const struct tm*)&thetime))
    {
        printf("strftime failed!\n");
        return -1;
    }
    return 0;
}

// This thread sets its locale to German
// and prints the time.
unsigned __stdcall SecondThreadFunc( void* pArguments )
{
    unsigned char str[BUFF_SIZE];

    // Set the thread code page
    _setmbcp(_MB_CP_ANSI)

    // Set the thread locale
    printf("The thread locale is now set to %s.\n",
           setlocale(LC_ALL, "German"));

    // Retrieve the time string from the helper function
    if (get_time(str) == 0)
    {
        printf("The time in German locale is: '%s'\n", str);
    }

    _endthreadex( 0 );
    return 0;
} 

// The main thread spawns a second thread (above) and then
// sets the locale to English and prints the time.
int main()
{ 
    HANDLE          hThread;
    unsigned        threadID;
    unsigned char   str[BUFF_SIZE];

    // Configure per-thread locale to cause all subsequently created 
    // threads to have their own locale.
    _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);

    // Retrieve the time string from the helper function
    printf("The thread locale is now set to %s.\n",
           setlocale(LC_ALL, "English"));

    // Create the second thread.
    hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc,
                                      NULL, 0, &threadID );

    if (get_time(str) == 0)
    {
        // Retrieve the time string from the helper function
        printf("The time in English locale is: '%s'\n\n", str);
    }

    // Wait for the created thread to finish.
    WaitForSingleObject( hThread, INFINITE );

    // Destroy the thread object.
    CloseHandle( hThread );
}
  
  
  
  

Odpowiednik w programie .NET Framework

Nie dotyczy. Jednakże, zobacz przy użyciu właściwości CurrentCulture.

Zobacz też

Informacje

setLocale, _wsetlocale

_beginthread, _beginthreadex

Ustawienia regionalne

Wielowątkowość i ustawień regionalnych