Structure to Api call

G

Guest

The following code is converted from VB6 to VS2005.
The call to GetLocaleInfoLS returns always 0.
Please HELP !!!!

<StructLayout(LayoutKind.Sequential)> _
Private Structure LOCALESIGNATURE
<VBFixedArray(3)> Dim lsUsb() As Integer
<VBFixedArray(1)> Dim lsCsbDefault() As Integer
<VBFixedArray(1)> Dim lsCsbSupported() As Integer
Public Sub Initialize()
ReDim lsUsb(3)
ReDim lsCsbDefault(1)
ReDim lsCsbSupported(1)
End Sub
End Structure
<StructLayout(LayoutKind.Sequential)> _
Private Structure CHARSETINFO
Dim ciCharset As Integer
Dim ciACP As Integer
Dim Fs As FONTSIGNATURE
Public Sub Initialize()
Fs = New FONTSIGNATURE
Fs.Initialize()
End Sub
End Structure

Private Const LOCALE_FONTSIGNATURE As Integer = &H58 ' font signature
Private Const TCI_SRCFONTSIG As Short = 3

Private Class Api

Declare Auto Function GetLocaleInfoLS Lib "kernel32" Alias
"GetLocaleInfoA" ( _
ByVal Locale As Integer, _
ByVal LCType As Integer, _
ByRef lpLCData As LOCALESIGNATURE, _
ByVal cchData As Integer) As Integer

Declare Auto Function TranslateCharsetInfo Lib "GDI32" ( _
ByRef lpSrc As Integer, _
ByRef lpcs As CHARSETINFO, _
ByVal dwFlags As Integer) As Integer
End Class


Private Function GetUserCharset() As Short
Dim ls As New LOCALESIGNATURE() ' local signature struct.
ls.Initialize()
Dim ci As New CHARSETINFO() ' character set info struct.
ci.Initialize()
Dim RC As Integer
Dim lsl As Integer = Marshal.SizeOf(ls)

' get locale signature based on the USER's Default LCID.
'
' what is wrong with this call ?????
'
RC =
Api.GetLocaleInfoLS(System.Globalization.CultureInfo.CurrentCulture.LCID, _
LOCALE_FONTSIGNATURE, ls, lsl)
If (RC > 0) Then ' if success
ls.lsCsbDefault(1) = 0 ' zero out bits
' translate charset info from locale fontsignature.
RC = Api.TranslateCharsetInfo(ls.lsCsbDefault(0), ci,
TCI_SRCFONTSIG)
If RC <> 0 Then GetUserCharset = ci.ciCharset ' return charset
End If
End Function
 
D

David Browne

Simos_V said:
The following code is converted from VB6 to VS2005.
The call to GetLocaleInfoLS returns always 0.
Please HELP !!!!

<StructLayout(LayoutKind.Sequential)> _
Private Structure LOCALESIGNATURE

....

In general you shoudn't try to use the API signatures the upgrade wizard
creates.


When upgrading VB6 API calls to .NET, first look to find equivilent
functionality in the .NET framework.


99% of the time you can just rip out the API declare and use the .NET
framework.

From
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/win32map.asp
GetLocaleInfo - Retrieves information about a locale.

Use
System.Globalization.CultureInfo.DateTimeFormat
System.Globalization.CultureInfo.NumberFormat
System.Globalization.CultureInfo.TextInfo


If that fails, look at www.pinvoke.net and find a tested API interop
signature.

If that fails, then you have to figure out the marshaling yourself.

David
 
G

Guest

Thank's David
In the future i will replace all Api calls with the .NET framework.
But i would prefer to have a runing project now before i will study and get
used to .NET framework
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top