Jump to content

WinCpTranslateString: Difference between revisions

From EDM2
Created page with "This function translates a string from one code page to another. ==Syntax== WinCpTranslateString(hab, idCpSource, pszSource, idCpDest, cbLenDest, pszDest); ==Parameters== ..."
 
Ak120 (talk | contribs)
mNo edit summary
Line 1: Line 1:
This function translates a string from one code page to another.  
This function translates a string from one code page to another.


==Syntax==
==Syntax==
  WinCpTranslateString(hab, idCpSource, pszSource, idCpDest, cbLenDest, pszDest);
  WinCpTranslateString(hab, idCpSource, pszSource, idCpDest, cbLenDest, pszDest)


==Parameters==
==Parameters==
; hab (HAB) - input
;hab (HAB) - input:Anchor-block handle.
:Anchor-block handle.  
;idCpSource (ULONG) - input:Source-string code page.
 
;pszSource (PSZ) - input:String to be translated.
;idCpSource (ULONG) - input
:This is a null-terminated string.
:Source-string code page.  
;idCpDest (ULONG) - input:Code page of the resultant string.
 
;cbLenDest (ULONG) - input:Maximum length of output string.
;pszSource (PSZ) - input
:An error is raised if this is not large enough to contain the translated string.
:String to be translated.
;pszDest (PSZ) - output:The translated string.
:This is a null-terminated string.  
 
;idCpDest (ULONG) - input
:Code page of the resultant string.  
 
;cbLenDest (ULONG) - input
:Maximum length of output string.
:An error is raised if this is not large enough to contain the translated string.  
 
;pszDest (PSZ) - output
:The translated string.
:This is a null-terminated string.
:This is a null-terminated string.


==Returns==
==Returns==
; rc (BOOL) - returns
;rc (BOOL) - returns: Success indicator.
: Success indicator.
::TRUE - Successful completion
:;TRUE
::FALSE - Error occurred.
::Successful completion  
:;FALSE
::Error occurred.


==Errors==
==Errors==
Possible returns from WinGetLastError
Possible returns from WinGetLastError
 
::PMERR_INVALID_STRING_PARM (0x100B) :The specified string parameter is invalid.
;PMERR_INVALID_STRING_PARM (0x100B)
::PMERR_INVALID_SRC_CODEPAGE (0x101D) :The source code page parameter is invalid.
:The specified string parameter is invalid.  
::PMERR_INVALID_DST_CODEPAGE (0x101E) :The destination code page parameter is invalid.
;PMERR_INVALID_SRC_CODEPAGE (0x101D)
::PMERR_PARAMETER_OUT_OF_RANGE (0x1003) :The value of a parameter was not within the defined valid range for that parameter.
:The source code page parameter is invalid.  
;PMERR_INVALID_DST_CODEPAGE (0x101E)
:The destination code page parameter is invalid.  
;PMERR_PARAMETER_OUT_OF_RANGE (0x1003)
:The value of a parameter was not within the defined valid range for that parameter.


==Remarks==
==Remarks==
Line 50: Line 31:


The following is the list of valid code pages:
The following is the list of valid code pages:
 
Country             Code Page
    Country
Canadian-French     863
        Code Page Canadian-French
Desktop Publishing 1004
        863 Desktop Publishing
Iceland             861
        1004 Iceland
Latin 1 Multilingual 850
        861 Latin 1 Multilingual
Latin 2 Multilingual 852
        850 Latin 2 Multilingual
Nordic               865
        852 Nordic
Portuguese           860
        865 Portuguese
Turkey               857
        860 Turkey
U.S. (IBM PC)       437  
        857 U.S. (IBM PC)
        437  
 
Code page 1004 is compatible with Microsoft** Windows**.
Code page 1004 is compatible with Microsoft** Windows**.


The following EBCDIC code pages, based on character set 697, are also available for output:
The following EBCDIC code pages, based on character set 697, are also available for output:
 
Country       Code Page
    Country
Austrian/German 273
        Code Page Austrian/German
Belgian         500
        273 Belgian
Brazil           037
        500 Brazil
Czechoslovakia   870
        037 Czechoslovakia
Danish/Norwegian 277
        870 Danish/Norwegian
Finnish/Swedish 278
        277 Finnish/Swedish
French           297
        278 French
Hungary         870
        297 Hungary
Iceland         871
        870 Iceland
International   500
        871 International
Italian         280
        500 Italian
Poland           870
        280 Poland
Portuguese       037
        870 Portuguese
Spanish         284
        037 Spanish
Turkey         1026
        284 Turkey
U.K.-English     285
        1026 U.K.-English
U.S.-English     037
        285 U.S.-English
Yugoslavia       870
        037 Yugoslavia
Code pages 274 (Belgian) and 282 (Portuguese) can be used to provide access to old data.
        870  
 
Code pages 274 (Belgian) and 282 (Portuguese) can be used to provide access to old data.  


==Example Code==
==Example Code==
This example translates a string from US code page 437 to multilingual code page 850.  
This example translates a string from US code page 437 to multilingual code page 850.
<pre>
<pre>
#define INCL_WINCOUNTRY        /* Window Country Functions    */
#define INCL_WINCOUNTRY        /* Window Country Functions    */
Line 103: Line 78:
ULONG  cbLenDest = 9L; /* max length of destination string    */
ULONG  cbLenDest = 9L; /* max length of destination string    */
BOOL    fSuccess;
BOOL    fSuccess;
strcpy(pszSource,"TRANSLATE");
strcpy(pszSource,"TRANSLATE");
fSuccess = WinCpTranslateString(hab, idCpSource, pszSource,
fSuccess = WinCpTranslateString(hab, idCpSource, pszSource,
                                 idCpDest, cbLenDest, pszDest);
                                 idCpDest, cbLenDest, pszDest);
</pre>
Definition
<pre>
#define INCL_WINCOUNTRY /* Or use INCL_WIN, INCL_PM, */
#include <os2.h>
HAB      hab;        /*  Anchor-block handle. */
ULONG    idCpSource;  /*  Source-string code page. */
PSZ      pszSource;  /*  String to be translated. */
ULONG    idCpDest;    /*  Code page of the resultant string. */
ULONG    cbLenDest;  /*  Maximum length of output string. */
PSZ      pszDest;    /*  The translated string. */
BOOL    rc;          /*  Success indicator. */
rc = WinCpTranslateString(hab, idCpSource,
      pszSource, idCpDest, cbLenDest, pszDest);
</pre>
</pre>



Revision as of 20:47, 21 November 2023

This function translates a string from one code page to another.

Syntax

WinCpTranslateString(hab, idCpSource, pszSource, idCpDest, cbLenDest, pszDest)

Parameters

hab (HAB) - input
Anchor-block handle.
idCpSource (ULONG) - input
Source-string code page.
pszSource (PSZ) - input
String to be translated.
This is a null-terminated string.
idCpDest (ULONG) - input
Code page of the resultant string.
cbLenDest (ULONG) - input
Maximum length of output string.
An error is raised if this is not large enough to contain the translated string.
pszDest (PSZ) - output
The translated string.
This is a null-terminated string.

Returns

rc (BOOL) - returns
Success indicator.
TRUE - Successful completion
FALSE - Error occurred.

Errors

Possible returns from WinGetLastError

PMERR_INVALID_STRING_PARM (0x100B) :The specified string parameter is invalid.
PMERR_INVALID_SRC_CODEPAGE (0x101D) :The source code page parameter is invalid.
PMERR_INVALID_DST_CODEPAGE (0x101E) :The destination code page parameter is invalid.
PMERR_PARAMETER_OUT_OF_RANGE (0x1003) :The value of a parameter was not within the defined valid range for that parameter.

Remarks

Successful invocation of this function indicates that either (1) the character was directly mapped into the destination code page or, (2) the substitution character (0xFF) was returned.

The following is the list of valid code pages:

Country             Code Page
Canadian-French      863
Desktop Publishing  1004
Iceland              861
Latin 1 Multilingual 850
Latin 2 Multilingual 852
Nordic               865
Portuguese           860
Turkey               857
U.S. (IBM PC)        437 

Code page 1004 is compatible with Microsoft** Windows**.

The following EBCDIC code pages, based on character set 697, are also available for output:

Country        Code Page
Austrian/German  273
Belgian          500
Brazil           037
Czechoslovakia   870
Danish/Norwegian 277
Finnish/Swedish  278
French           297
Hungary          870
Iceland          871
International    500
Italian          280
Poland           870
Portuguese       037
Spanish          284
Turkey          1026
U.K.-English     285
U.S.-English     037
Yugoslavia       870

Code pages 274 (Belgian) and 282 (Portuguese) can be used to provide access to old data.

Example Code

This example translates a string from US code page 437 to multilingual code page 850.

#define INCL_WINCOUNTRY         /* Window Country Functions     */
#include <os2.h>

HAB     hab;            /* anchor-block handle                  */
ULONG   idCpSource=437; /* Code page of source character (US)   */
ULONG   idCpDest=850;   /* Code page of dest. character (multi) */
char    pszSource[10];  /* source string                        */
char    pszDest[10];    /* destination string                   */
ULONG   cbLenDest = 9L; /* max length of destination string     */
BOOL    fSuccess;

strcpy(pszSource,"TRANSLATE");
fSuccess = WinCpTranslateString(hab, idCpSource, pszSource,
                                idCpDest, cbLenDest, pszDest);

Related Functions

  • WinCpTranslateChar
  • WinQueryCp
  • WinQueryCpList
  • WinSetCp