ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzaik_5.4.0.1/rzaiknlsprogex.htm

179 lines
7.6 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Example: iSeries Access for Windows NLS APIs" />
<meta name="abstract" content="This example illustrates using iSeries Access for Windows NLS APIs." />
<meta name="description" content="This example illustrates using iSeries Access for Windows NLS APIs." />
<meta name="DC.Relation" scheme="URI" content="rzaiknls.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1999, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1999, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="nlsprogex" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Example: iSeries Access for Windows NLS
APIs</title>
</head>
<body id="nlsprogex"><a name="nlsprogex"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: <span class="keyword">iSeries Access for Windows</span> NLS
APIs</h1>
<div><p>This example illustrates using <span class="keyword">iSeries™ Access for Windows<sup>®</sup></span> NLS
APIs.</p>
<div class="example"> <pre>
/* National Language Support Code Snippet */
/* Used to demonstrate how the APIs would be run. */
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include "CWBNL.H"
#include "CWBNLCNV.H"
#include "CWBSV.H"
cwbSV_ErrHandle errhandle;
/* Return the message text associated with the top-level */
/* error identified by the error handle provided. Since */
/* all APIs that fail use the error handle, this was moved */
/* into a separate routine. */
void resolveErr(cwbSV_ErrHandle errhandle)
{
static unsigned char buf[ BUFSIZ ];
unsigned long retlen;
unsigned int rc;
if ((rc = cwbSV_GetErrText(errhandle, buf, (unsigned long) BUFSIZ, &amp;retlen)) != CWB_OK)
printf("cwbSV_GetErrText() Service API failed with return code 0x%x.\n", rc);
else
printf("%s\n", (char *) buf);
}
void main(void){
/* define some variables
-------------------- */
int SVrc = 0;
int NLrc = 0;
char *myloadpath = "";
char *resultPtr;
char *mylang;
unsigned short resultlen;
unsigned short reqlen;
unsigned long searchhandle;
unsigned long codepage;
unsigned long trgtpage;
char *srcbuf = "Change this string";
char *trgtbuf;
unsigned long srclen;
unsigned long trgtlen;
unsigned long nmbrerrs;
unsigned long posoferr;
unsigned long rqdlen;
unsigned long ccsid;
/* Create an error message object and return a handle to */
/* it. This error handle can be passed to APIs that */
/* support it. If an error occurs, the error handle can */
/* be used to retrieve the message text associated with */
/* the API error. */
SVrc = cwbSV_CreateErrHandle(&amp;errhandle);
if (SVrc != CWB_OK) {
printf("cwbSV_CreateErrHandle failed with return code %d.\n", SVrc);
}
/* Retreive the current language setting. */
resultlen = CWBNL_MAX_LANG_SIZE+1;
resultPtr = (char *) malloc(resultlen * sizeof(char));
NLrc = cwbNL_GetLang(myloadpath, resultPtr, resultlen, &amp;reqlen, errhandle);
if (NLrc != CWB_NO_ERR) {
if (NLrc == CWB_BUFFER_TOO_SMALL)
printf("GetLang buffer too small, recommended size %d.\n", reqlen);
resolveErr(errhandle);
}
printf("GetLang API returned %s.\n", resultPtr);
mylang = (char *) malloc(resultlen * sizeof(char));
strcpy(mylang, resultPtr);
/* Retrieve the descriptive name of a language setting. */
resultlen = CWBNL_MAX_NAME_SIZE+1;
resultPtr = (char *) realloc(resultPtr, resultlen * sizeof(char));
NLrc = cwbNL_GetLangName(mylang, resultPtr, resultlen, &amp;reqlen, errhandle);
if (NLrc != CWB_NO_ERR) {
if (NLrc == CWB_BUFFER_TOO_SMALL)
printf("GetLangName buffer too small, recommended size %d.\n", reqlen);
resolveErr(errhandle);
}
printf("GetLangName API returned %s.\n", resultPtr);
/* Return the complete path for language files. */
resultlen = CWBNL_MAX_PATH_SIZE+1;
resultPtr = (char *) realloc(resultPtr, resultlen * sizeof(char));
NLrc = cwbNL_GetLangPath(myloadpath, resultPtr, resultlen, &amp;reqlen, errhandle);
if (NLrc != CWB_NO_ERR) {
if (NLrc == CWB_BUFFER_TOO_SMALL)
printf("GetLangPath buffer too small, recommended size %d.\n", reqlen);
resolveErr(errhandle);
}
printf("GetLangPath API returned %s.\n", resultPtr);
/* Get the code page of the current process. */
NLrc = cwbNL_GetCodePage(&amp;codepage, errhandle);
if (NLrc != CWB_NO_ERR) {
resolveErr(errhandle);
}
printf("GetCodePage API returned %u.\n", codepage);
/* Convert strings from one code page to another. This */
/* API combines three converter APIs for the default */
/* conversion. The three converter APIs it combines are: */
/* cwbNL_CreateConverterEx */
/* cwbNL_Convert */
/* cwbNL_DeleteConverter */
srclen = strlen(srcbuf) + 1;
trgtlen = srclen;
trgtpage = 437;
trgtbuf = (char *) malloc(trgtlen * sizeof(char));
printf("String to convert is %s.\n",srcbuf);
NLrc = cwbNL_ConvertCodePagesEx(codepage, trgtpage, srclen,
trgtlen, srcbuf, trgtbuf, &amp;nmbrerrs, &amp;posoferr, &amp;rqdlen,
errhandle);
if (NLrc != CWB_NO_ERR) {
resolveErr(errhandle);
printf("number of errors detected is %u.\n", nmbrerrs);
printf("location of first error is %u.\n", posoferr);
}
printf("ConvertCodePagesEx API returned %s.\n", trgtbuf);
/* Map a code page to the corresponding CCSID. */
NLrc = cwbNL_CodePageToCCSID(codepage, &amp;ccsid, errhandle);
if (NLrc != CWB_NO_ERR) {
resolveErr(errhandle);
}
printf("CodePageToCCSID returned %u.\n", ccsid);
cwbSV_DeleteErrHandle(errhandle);
}</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzaiknls.htm" title="iSeries Access for Windows national language support APIs enable your applications to get and save (query and change) the iSeries Access for Windows settings that are relevant to national language support.">iSeries Access for Windows national language support (NLS) APIs</a></div>
</div>
</div>
</body>
</html>