Hm,
das ist komisch.
Mit diesem Code lese ich das Land aus, das an dem PC eingestellt ist:
Spoiler anzeigen
Funktioniert wunderbar.
Wenn ich das allerdings in einer Console-Anwendung machen möchte:
Spoiler anzeigen
Dann krieg ich den Fehler:
Ungültige Konvertierung von der Zeichenfolge Germany in Typ Integer.
Woran liegt das?
das ist komisch.
Mit diesem Code lese ich das Land aus, das an dem PC eingestellt ist:
VB.NET-Quellcode
- Imports System.Runtime.InteropServices
- Public Class Form1
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- MsgBox((GetInfo(LOCALE_SENGCOUNTRY)))
- End Sub
- <DllImport("kernel32.dll")> _
- Private Shared Function GetLocaleInfo(ByVal Locale As UInteger, ByVal LCType As UInteger, <Out()> ByVal lpLCData As System.Text.StringBuilder, ByVal cchData As Integer) As Integer
- End Function
- Private Const LOCALE_SYSTEM_DEFAULT As UInteger = &H400
- Private Const LOCALE_SENGCOUNTRY As UInteger = &H1002
- Private Shared Function GetInfo(ByVal lInfo As UInteger) As String
- Dim lpLCData = New System.Text.StringBuilder(256)
- Dim ret As Integer = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, lInfo, lpLCData, lpLCData.Capacity)
- If ret > 0 Then
- Return lpLCData.ToString().Substring(0, ret - 1)
- End If
- Return String.Empty
- End Function
- Public Shared Function GetLetters()
- Dim MyCountry As String = (GetInfo(LOCALE_SENGCOUNTRY))
- Return MyCountry
- End Function
- End Class
Funktioniert wunderbar.
Wenn ich das allerdings in einer Console-Anwendung machen möchte:
VB.NET-Quellcode
- Imports System.Runtime.InteropServices
- Module Module1
- Sub Main()
- WriteLine(GetInfo(LOCALE_SENGCOUNTRY))
- End Sub
- <DllImport("kernel32.dll")> _
- Private Function GetLocaleInfo(ByVal Locale As UInteger, ByVal LCType As UInteger, <Out()> ByVal lpLCData As System.Text.StringBuilder, ByVal cchData As Integer) As Integer
- End Function
- Private Const LOCALE_SYSTEM_DEFAULT As UInteger = &H400
- Private Const LOCALE_SENGCOUNTRY As UInteger = &H1002
- Private Function GetInfo(ByVal lInfo As UInteger) As String
- Dim lpLCData = New System.Text.StringBuilder(256)
- Dim ret As Integer = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, lInfo, lpLCData, lpLCData.Capacity)
- If ret > 0 Then
- Return lpLCData.ToString().Substring(0, ret - 1)
- End If
- Return String.Empty
- End Function
- Public Function GetLetters()
- Dim MyCountry As String = (GetInfo(LOCALE_SENGCOUNTRY))
- Return MyCountry
- End Function
- End Module
Dann krieg ich den Fehler:
Ungültige Konvertierung von der Zeichenfolge Germany in Typ Integer.
Woran liegt das?
C# Developer
Learning C++
Learning C++