_configthreadlocale
İş parçacığı başına yerel ayar seçeneklerini yapılandırır.
int _configthreadlocale(
int type
);
Parametreler
- type
Ayarlamak için seçenek.Aşağıdaki tabloda listelenen seçeneklerden biri.
Dönüş Değeri
Önceki iş parçacığı başına yerel ayar durumu (_DISABLE_PER_THREAD_LOCALE veya _ENABLE_PER_THREAD_LOCALE), veya hata durumunda -1.
Notlar
_configurethreadlocale İşlevi iş parçacığına özgü yerel ayarların kullanımını denetlemek için kullanılır.İş parçacığı başına yerel ayar durumunu belirlemek için aşağıdaki seçeneklerden birini kullanın:
_ENABLE_PER_THREAD_LOCALE
Geçerli iş parçacığı kullanım iş parçacığına özgü yerel olun.Sonraki aramalar için setlocale bu iş parçacığı parçacığının kendi yerel etkiler._DISABLE_PER_THREAD_LOCALE
Geçerli iş parçacığı genel yerel ayar kullanmak olun.Sonraki aramalar için setlocale bu iş parçacığında genel yerel ayar kullanarak diğer iş parçacıklarını etkiler.0
Bu belirli bir iş parçacığı için geçerli ayarı alır.
These functions affect the behavior of setlocale, _tsetlocale, _wsetlocale, _beginthread, and _beginthreadex.İş parçacığı oluşturmak için kullanılan başka bir yöntem, yerel ayarları bu iş parçacığı üzerinde etkisi yoktur.
İş parçacığı başına yerel ayar devre dışı bırakılırsa, sonraki çağrı olduğunda setlocale veya _wsetlocale tüm iş parçacığı yerel ayarı değiştirir.İş parçacığı başına yerel ayar etkin olduğunda, setlocale veya _wsetlocale yalnızca geçerli iş parçacığı yerel ayar etkiler.
Kullanırsanız, _configurethreadlocale bir iş parçacığı başına yerel ayarı etkinleştirmek için arama öneririz setlocale veya _wsetlocale hemen sonra bu iş parçacığında tercih edilen yerel ayarı belirlemek için.
type Değerlerden biri değil tabloda listelenen, bu işlevi geçersiz bir parametre işleyicisi açıklandığı gibi çağırır Parametre doğrulama.Bu işlev yürütülmesine devam etmek için izin verilirse, ayarlar errno için EINVAL ve -1 değerini döndürür.
Gereksinimler
Yordamı |
Gerekli başlık |
---|---|
_configthreadlocale |
<locale.h> |
Örnek
// 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(<ime);
_gmtime64_s(&thetime, <ime);
// 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 );
}
.NET Framework Eşdeğeri
Yoktur. Ancak, CurrentCulture özelliğini kullanarak.