Ignore:
Timestamp:
Jun 2, 2007, 7:04:19 PM (17 years ago)
Author:
イグトランス (egtra)
Message:

StringのResizeを呼ぶコンストラクタでメモリ確保されない場合を排除、ほか微修正

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Include/Classes/System/Environment.ab

    r258 r268  
    33#require <api_psapi.sbp>
    44#require <Classes/System/OperatingSystem.ab>
     5#require <Classes/ActiveBasic/Windows/index.ab>
     6
     7Declare Function _System_SetEnvironmentVariable Lib "kernel32" Alias _FuncName_SetEnvironmentVariable (lpName As LPCTSTR, lpValue As LPTSTR) As BOOL
     8Declare Function _System_GetEnvironmentVariable Lib "kernel32" Alias _FuncName_GetEnvironmentVariable (lpName As PCTSTR, lpBuffer As PTSTR, nSize As DWord) As DWord
    59
    610Namespace System
     
    812Namespace Detail
    913    TypeDef PFNGetProcessMemoryInfo = *Function(Process As HANDLE, ByRef mc As PROCESS_MEMORY_COUNTERS, cb As DWord) As BOOL
     14
     15    Dim hasShutdownStarted As Boolean
    1016End Namespace
    1117
     
    4854
    4955    Static Function HasShutdownStarted() As Boolean
    50         Return False
     56        Return Detail.hasShutdownStarted
    5157    End Function
    5258
     
    5965        End If
    6066        Return machineName
    61     End Function           
     67    End Function
    6268
    6369    Static Function NewLine() As String
     
    9298            sysDir = New String(p, len As Long)
    9399            _System_free(p)
    94         End IF
     100        End If
    95101        Return sysDir
    96102    End Function
     
    112118        End If
    113119        Return userName
    114     End Function           
     120    End Function
    115121
    116122    ' Version
     
    126132            If pGetProcessMemoryInfo(GetCurrentProcess(), mc, Len (mc)) <> FALSE Then
    127133                WorkingSet = mc.WorkingSetSize
    128                
    129134            End If
    130135        End If
     
    154159    ' GetCommandLineArgs
    155160
    156     ' GetEnvironmentVariable
     161    Static Function GetEnvironmentVariable(variable As String) As String
     162        Dim tcsVariable = ToTCStr(variable)
     163        Dim size = _System_GetEnvironmentVariable(tcsVariable, 0, 0)
     164        Dim p = _System_malloc(SizeOf (TCHAR) * size) As PTSTR
     165        Dim len = _System_GetEnvironmentVariable(tcsVariable, p, size)
     166        GetEnvironmentVariable = New String(p, len As Long)
     167        _System_free(p)
     168    End Function
    157169
    158170    ' GetEnvironmentVariables
     
    169181    ' GetLogicalDrives
    170182
    171     ' SetEnvironmentVariable
     183    Static Sub SetEnvironmentVariable(variable As String, value As String)
     184        _System_SetEnvironmentVariable(ToTCStr(variable), ToTCStr(value))
     185    End Sub
    172186
    173187Private
     
    207221End Enum
    208222
    209 
    210223End Namespace 'System
Note: See TracChangeset for help on using the changeset viewer.