Unicode文字列をANSI文字列に変換          <TOP>


Unicode文字列をANSI文字列に変換します。

GetTimeZoneInformation 現在のタイムゾーンのパラメータを取得

WideCharToMultiByte Unicode文字列をANSI文字列に変換

 

例では直接取得したStandardName・DaylightNameと、それらの変換後を表示しています。

 

'================================================================
'= Unicode文字列をANSI文字列に変換
'=    (WideCharToMultiByte.bas)
'================================================================
#include "Windows.bi"

Type SYSTEMTIME
    wYear         As Integer
    wMonth        As Integer
    wDayOfWeek    As Integer
    wDay          As Integer
    wHour         As Integer
    wMinute       As Integer
    wSecond       As Integer
    wMilliseconds As Integer
End Type
 
Type TIME_ZONE_INFORMATION
    Bias As Long
    StandardName As String * 64
    StandardDate As SYSTEMTIME
    StandardBias As Long
    DaylightName As String * 64
    DaylightDate As SYSTEMTIME
    DaylightBias As Long
End Type
 
' 現在のタイムゾーンのパラメータを取得
Declare Function Api_GetTimeZoneInformation& Lib "kernel32" Alias "GetTimeZoneInformation" (lpTimeZoneInformation As TIME_ZONE_INFORMATION)

' Unicode文字列をANSI文字列に変換
Declare Function Api_WideCharToMultiByte& Lib "kernel32" Alias "WideCharToMultiByte" (ByVal CodePage&, ByVal dwFlags&, ByVal lpWideCharStr$, ByVal cchWideChar&, ByVal lpMultiByteStr$, ByVal cchMultiByte&, ByVal lpDefaultChar$, ByVal lpUsedDefaultChar&)

Var tzi As TIME_ZONE_INFORMATION
Var TmpOut As String * 32
Var Ret As Long
   
'タイムゾーン情報取得
Ret = Api_GetTimeZoneInformation(tzi)

Print "変換前"
Print tab(4) & "タイムゾーン:" & left$(tzi.StandardName, instr(tzi.StandardName, Chr$(0)) - 1)
Print tab(4) & "サマータイム:" & left$(tzi.DaylightName, instr(tzi.DaylightName, Chr$(0)) - 1)

Print "変換後"
'タイムゾーンをUnicodeからANSIに変換
Ret = Api_WideCharToMultiByte(0, 0, tzi.StandardName, 64, TmpOut, 32, "", 0)
Print tab(4) & "タイムゾーン:" &  left$(TmpOut, instr(1, TmpOut, Chr$(0)) - 1)
   
'サマータイムをUnicodeからANSIに変換
Ret = Api_WideCharToMultiByte(0, 0, tzi.DaylightName, 64, TmpOut, 32, "", 0)
Print tab(4) & "サマータイム:" &  left$(TmpOut, instr(1, TmpOut, Chr$(0)) - 1)

Stop
End