_configthreadlocale

Configurar las opciones de configuración regional de por- subproceso.

int _configthreadlocale(
   int type
);

Parámetros

  • type
    Opción que se va a establecer.Una de las opciones enumeradas en la tabla siguiente.

Valor devuelto

El estado anterior de la configuración regional de por- subproceso (_DISABLE_PER_THREAD_LOCALE o _ENABLE_PER_THREAD_LOCALE), o -1 en el error.

Comentarios

La función de _configurethreadlocale se utiliza para controlar el uso de las configuraciones regionales subproceso- concretas.Utilice una de estas opciones para especificar o de determinar el estado de la configuración regional de por- subproceso:

  • _ENABLE_PER_THREAD_LOCALE
    Haga que el subproceso actual utiliza una configuración regional subproceso- concreta.Las llamadas subsiguientes a setlocale en este subproceso afectan solamente a la propia configuración regional del subproceso.

  • _DISABLE_PER_THREAD_LOCALE
    Haga que el subproceso actual utiliza la configuración regional global.Las llamadas subsiguientes a setlocale en este subproceso afectan a otros subprocesos con la configuración regional global.

  • 0
    Recupera el valor actual de este subproceso concreto.

Estas funciones afectan al comportamiento de setlocale, de _tsetlocale, de _wsetlocale, de _beginthread, y de _beginthreadex.Si otro método se utiliza para crear subprocesos, configuraciones regionales no tienen ningún efecto en esos subprocesos.

Cuando se deshabilita la configuración regional de por- subproceso, cualquier llamada subsiguiente a setlocale o a _wsetlocale cambia la configuración regional de todos los subprocesos.Cuando se habilita la configuración regional de por- subproceso, setlocale o _wsetlocale afecta sólo a la configuración regional del subproceso actual.

Si utiliza _configurethreadlocale para habilitar una configuración regional de por- subproceso, se recomienda llamar setlocale o _wsetlocale para establecer la configuración regional preferida en ese subproceso inmediatamente después.

Si type no es uno de los valores enumerados en la tabla, esta función invoca el controlador no válido de parámetro, tal y como se describe en Validación de parámetros.Si la ejecución puede continuar, conjuntos errno de esta función a EINVAL y devuelven -1.

Requisitos

Rutina

Encabezado necesario

_configthreadlocale

<locale.h>

Ejemplo

// 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 );
}
  
  
  
  

Equivalente en .NET Framework

No es aplicable Sin embargo, vea Mediante la propiedad CurrentCulture.

Vea también

Referencia

setlocale, _wsetlocale

_beginthread, _beginthreadex

Configuración regional

Subprocesamiento múltiple y configuraciones regionales