Solved

How to call Kernel32 GetCPInfoEx

Posted on 2001-06-23
10
835 Views
Last Modified: 2007-12-19
I have the following (I trimmed the rest of the code) coded:

Public Type CPINFOEX
  MaxCharSize As Long
  DefaultChar() As Byte
  LeadByte() As Byte
  UnicodeDefaultChar As Byte
  CodePage As Integer
  CodePageName As String * 128
End Type

Public Declare Function GetCPInfoEx Lib "kernel32" Alias "GetCPInfoExA" (ByVal CodePage As Long, ByVal Flags As Long, lpCPInfo As CPINFO) As Long

    Dim cpi As Long
    Dim lpCharSet As CPINFOEX

     cpi = 0
     lpCharSet.CodePageName = Space$(128)
     cpi = GetCPInfoEx(oSQL_Server.CodePage, cpi, lpCharSet)

However it does not work. There seems to be a mismatch in the lpCPInfo structure. Can anyone tell me what the correct calling structure within VB is please.

I do not want to call the GetCPInfo DLL as its only the Extended version that gives me what I want (the Code Page Name given a code page number).

I took the definitions from the Windows SDK.

Also does anyone have a mapping between DLL Data types and VB data types. I know about the API viewer. But it only helps so far and does not list the GetCPInfoEx function at all.

Regards,

Graham

0
Comment
Question by:Felicitous
  • 6
  • 3
10 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6221995
I think structure is missed. Take a look at this:

CPINFOEX
[This is preliminary documentation and subject to change.]

The CPINFOEX structure contains information about a code page. It is used by the GetCPInfoEx function.

typedef struct _cpinfoex {
    UINT    MaxCharSize;
    BYTE    DefaultChar[MAX_DEFAULTCHAR];
    BYTE    LeadByte[MAX_LEADBYTES];
    WCHAR   UnicodeDefaultChar;
    UINT    CodePage;
    TCHAR   CodePageName[MAX_PATH];
} CPINFOEX *LPCPINFOEX;
 
Members
MaxCharSize
Specifies the maximum length, in bytes, of a character in the code page.
DefaultChar
Specifies the default character used when translating character strings into this code page. This character is used by the WideCharToMultiByte function if an explicit default character is not given.
LeadByte
Specifies a fixed-length array of lead-byte ranges, where the number of lead-byte ranges is variable. If there are no lead bytes in this code page, every element of the array is NULL. If there are lead bytes in this code page, the array contains a starting and ending value for each range. Ranges are inclusive. The maximum number of lead-byte ranges for any code page is 5. The array uses 2 bytes to describe each range, with a double-byte null terminator after the last range.
UnicodeDefaultChar
Specifies the Unicode default character used in translations from this code page. This character is used by the MultiByteToWideChar function.
CodePage
Specifies the code page value.
CodePageName
Specifies the full, localized name of the code page.
Remarks
Lead bytes are unique to double-byte character sets (DBCS). A lead byte is the first byte of a 2-byte character in a DBCS. Lead bytes occupy a specific range of byte values.
0
 

Author Comment

by:Felicitous
ID: 6222048
Hmmm,

thanks for info but most of this I already know. I am trying to get the code page name given its number. Therefore at point of calling I do not know anything else but the UINT CodePage.

I do not know the MAX_DEFAULTCHAR or MAX_LEADBYTES.

The detail is useful but does not help my cause. Can you help a little further and maybe give me a working example. I have tried just about everything to get this working and it just will not behave.

I am writing in Visual Basic 6 SP5 and I am not a great C++ programmer.

Regards,

Graham
0
 

Author Comment

by:Felicitous
ID: 6222068
Hmmm,

thanks for info but most of this I already know. I am trying to get the code page name given its number. Therefore at point of calling I do not know anything else but the UINT CodePage.

I do not know the MAX_DEFAULTCHAR or MAX_LEADBYTES.

The detail is useful but does not help my cause. Can you help a little further and maybe give me a working example. I have tried just about everything to get this working and it just will not behave.

I am writing in Visual Basic 6 SP5 and I am not a great C++ programmer.

Regards,

Graham
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 100 total points
ID: 6222242
Well, that is what i found

#define MAX_LEADBYTES             12          // 5 ranges, 2 bytes ea., 0 term.
#define MAX_DEFAULTCHAR           2           // single or double byte

If i understood that notation, they should become:
const MAX_LEADBYTES = 12
const MAX_DEFAULTCHAR = 2
0
 
LVL 2

Expert Comment

by:hangman
ID: 6223541
The structure you are using is wrong. In the DLL declaration, it needs a CPINFO structure which looks like

struct _cpinfo {
    UINT MaxCharSize;
    BYTE DefaultChar[MAX_DEFAULTCHAR];
    BYTE LeadByte[MAX_LEADBYTES];
} CPINFO;
 
not the CPINFOEX
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Felicitous
ID: 6223813
Hi, (re Hangman Post)

I believe from the SDK there are two functions.

GetCPInfoEx which uses the Extended structure (CPINFOEX).

GetCPInfo which uses the standard structure (CPINFO).

I need the extended structure to get the code page name.

Regards,

Graham
0
 

Author Comment

by:Felicitous
ID: 6223817
Richie,

I will try your solution this evening and get back to you. Thanks for the further info.

The structure I will now try is as follows:

Public Type CPINFOEX
 MaxCharSize As Long
 DefaultChar(2) As Byte
 LeadByte(12) As Byte
 UnicodeDefaultChar As Byte
 CodePage As Integer
 CodePageName As String * 128
End Type

If you think it is wrong please post here.

Kind Regards,

Graham
0
 

Author Comment

by:Felicitous
ID: 6223825
Hmmm,

with the lead from hangman and a re-read of my code it looks like I may have coded the Declare incorrectly.

Public Declare Function GetCPInfoEx Lib "kernel32" Alias "GetCPInfoExA" (ByVal CodePage As Long, ByVal
Flags As Long, lpCPInfo As CPINFO) As Long

Prehaps the following would help:

Public Declare Function GetCPInfoEx Lib "kernel32" Alias "GetCPInfoExA" (ByVal CodePage As Long, ByVal
Flags As Long, lpCPInfo As CPINFOEX) As Long

I may have a combination of problems. (Apart from me :-) )

Regards,

Graham
0
 

Author Comment

by:Felicitous
ID: 6225735
Richie,

thanks for the info. The lengths did the trick.

Regards,

Graham
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6225773
Uf, at least!
Sorry for delay, i was in problems with Internet connection an EE .
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now