12e5b6d6dSopenharmony_ci--- 22e5b6d6dSopenharmony_cilayout: default 32e5b6d6dSopenharmony_cititle: Cobol 42e5b6d6dSopenharmony_cinav_order: 1 52e5b6d6dSopenharmony_ciparent: Use From... 62e5b6d6dSopenharmony_ci--- 72e5b6d6dSopenharmony_ci<!-- 82e5b6d6dSopenharmony_ci© 2020 and later: Unicode, Inc. and others. 92e5b6d6dSopenharmony_ciLicense & terms of use: http://www.unicode.org/copyright.html 102e5b6d6dSopenharmony_ci--> 112e5b6d6dSopenharmony_ci 122e5b6d6dSopenharmony_ci# How To Use ICU4C From COBOL 132e5b6d6dSopenharmony_ci{: .no_toc } 142e5b6d6dSopenharmony_ci 152e5b6d6dSopenharmony_ci## Contents 162e5b6d6dSopenharmony_ci{: .no_toc .text-delta } 172e5b6d6dSopenharmony_ci 182e5b6d6dSopenharmony_ci1. TOC 192e5b6d6dSopenharmony_ci{:toc} 202e5b6d6dSopenharmony_ci 212e5b6d6dSopenharmony_ci--- 222e5b6d6dSopenharmony_ci 232e5b6d6dSopenharmony_ci## Overview 242e5b6d6dSopenharmony_ci 252e5b6d6dSopenharmony_ciThis document describes how to use ICU functions within a COBOL program. It is 262e5b6d6dSopenharmony_ciassumed that the programmer understands the concepts behind ICU, and is able to 272e5b6d6dSopenharmony_ciidentify which ICU APIs are appropriate for his/her purpose. The programmer must 282e5b6d6dSopenharmony_cialso understand the meaning of the arguments passed to these APIs and of the 292e5b6d6dSopenharmony_cireturned value, if any. This is all explained in the ICU documentation, although 302e5b6d6dSopenharmony_ciin C/C++ style. This document’s objective is to facilitate the adaptation of 312e5b6d6dSopenharmony_cithese explanations to COBOL syntax. 322e5b6d6dSopenharmony_ci 332e5b6d6dSopenharmony_ciIt must be understood that the packaging of ICU data and executable code into 342e5b6d6dSopenharmony_cilibraries is platform dependent. Consequently, the calling conventions between 352e5b6d6dSopenharmony_ciCOBOL programs and the C/C++ functions in ICU may vary from platform to 362e5b6d6dSopenharmony_ciplatform. In a lesser way, the C/C++ types of arguments and return values may 372e5b6d6dSopenharmony_cihave different equivalents in COBOL, depending on the platform and even the 382e5b6d6dSopenharmony_cispecific COBOL compiler used. 392e5b6d6dSopenharmony_ci 402e5b6d6dSopenharmony_ciThis document is supplemented with three [sample 412e5b6d6dSopenharmony_ciprograms](https://sourceforge.net/projects/icu/files/OldFiles/samples/ICU-COBOL.zip) 422e5b6d6dSopenharmony_ciillustrating using ICU APIs for code page conversion, collation and 432e5b6d6dSopenharmony_cinormalization. Description of the sample programs appears in the appendix at the 442e5b6d6dSopenharmony_ciend of this document. 452e5b6d6dSopenharmony_ci 462e5b6d6dSopenharmony_ci## ICU API invocation in COBOL 472e5b6d6dSopenharmony_ci 482e5b6d6dSopenharmony_ci1. Invocation of ICU APIs is done with the COBOL “CALL” statement. 492e5b6d6dSopenharmony_ci 502e5b6d6dSopenharmony_ci2. Variables, pointers and constants appearing in ICU \*.H files (for C/C++) 512e5b6d6dSopenharmony_ci must be defined in the WORKING-STORAGE section for COBOL. 522e5b6d6dSopenharmony_ci 532e5b6d6dSopenharmony_ci3. Arguments to a C/C++ API translate into arguments to a COBOL CALL statement, 542e5b6d6dSopenharmony_ci passed by value or by reference as will be detailed below. 552e5b6d6dSopenharmony_ci 562e5b6d6dSopenharmony_ci4. For a C/C++ API with a non-void return value, the RETURNING clause will be 572e5b6d6dSopenharmony_ci used for the CALL statement. 582e5b6d6dSopenharmony_ci 592e5b6d6dSopenharmony_ci5. Character string arguments to C/C++ must be null-terminated. In COBOL, this 602e5b6d6dSopenharmony_ci means using the `Z"xxx"` format for literals, and adding `X"00"` at the end of 612e5b6d6dSopenharmony_ci the content of variables. 622e5b6d6dSopenharmony_ci 632e5b6d6dSopenharmony_ci6. Special consideration must be given when a pointer is the value returned by 642e5b6d6dSopenharmony_ci an API, since COBOL implements a more limited concept of pointers than 652e5b6d6dSopenharmony_ci C/C++. How to handle this case will be explained below. 662e5b6d6dSopenharmony_ci 672e5b6d6dSopenharmony_ci### COBOL and C/C++ Data Types 682e5b6d6dSopenharmony_ci 692e5b6d6dSopenharmony_ciThe following table (extracted from IBM VisualAge COBOL documentation) shows the 702e5b6d6dSopenharmony_cicorrespondence between the data types available in COBOL and C/C++. 712e5b6d6dSopenharmony_ci 722e5b6d6dSopenharmony_ci> :point_right: **Note**: Parts of identifier names in Cobol are separated by `-`, not by `_` as in C. 732e5b6d6dSopenharmony_ci 742e5b6d6dSopenharmony_ci| C/C++ data types | COBOL data types | 752e5b6d6dSopenharmony_ci|--------------------------- |--------------------------------------------------------------------------------------------------- | 762e5b6d6dSopenharmony_ci| wchar_t | "DISPLAY-1 (PICTURE N, G) wchar_t is the processing code whereas DISPLAY-1 is the file code." | 772e5b6d6dSopenharmony_ci| char | PIC X. | 782e5b6d6dSopenharmony_ci| signed char | No appropriate COBOL equivalent. | 792e5b6d6dSopenharmony_ci| unsigned char | No appropriate COBOL equivalent. | 802e5b6d6dSopenharmony_ci| short signed int | PIC S9-S9(4) COMP-5. Can beCOMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 812e5b6d6dSopenharmony_ci| short unsigned int | PIC 9-9(4) COMP-5. Can be COMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 822e5b6d6dSopenharmony_ci| long int | PIC 9(5)-9(9) COMP-5. Can be COMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 832e5b6d6dSopenharmony_ci| long long int | PIC 9(10)-9(18) COMP-5. Can be COMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 842e5b6d6dSopenharmony_ci| float | COMP-1. | 852e5b6d6dSopenharmony_ci| double | COMP-2. | 862e5b6d6dSopenharmony_ci| enumeration | Equivalent to level 88, but not identical. | 872e5b6d6dSopenharmony_ci| char(n) | PICTURE X(n). | 882e5b6d6dSopenharmony_ci| array pointer (*) to type | No appropriate COBOL equivalent. | 892e5b6d6dSopenharmony_ci| pointer(*) to function | PROCEDURE-POINTER. | 902e5b6d6dSopenharmony_ci 912e5b6d6dSopenharmony_ciA number of C definitions specific to ICU (and many other compilers on POSIX 922e5b6d6dSopenharmony_ciplatforms) that are not presented in the table above can also be translated into 932e5b6d6dSopenharmony_ciCOBOL definitions. 942e5b6d6dSopenharmony_ci 952e5b6d6dSopenharmony_ci| C/C++ data types | COBOL data types | 962e5b6d6dSopenharmony_ci|------------------------------------------|---------------------------------------------------------------------------------------------| 972e5b6d6dSopenharmony_ci| int8_t | PIC X. Not really equivalent. | 982e5b6d6dSopenharmony_ci| uint8_t | PIC X. Not really equivalent. | 992e5b6d6dSopenharmony_ci| int16_t | PIC S9(4) BINARY. Can beCOMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 1002e5b6d6dSopenharmony_ci| uint16_t | PIC 9(4) BINARY. Can beCOMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 1012e5b6d6dSopenharmony_ci| int32_t | PIC S9(9) COMP-5. Can be COMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 1022e5b6d6dSopenharmony_ci| uint32_t | PIC 9(9) COMP-5. Can be COMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 1032e5b6d6dSopenharmony_ci| Uchar | PIC 9(4) BINARY. Can beCOMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 1042e5b6d6dSopenharmony_ci| Uchar32 | PIC 9(9) COMP-5. Can be COMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 1052e5b6d6dSopenharmony_ci| UNormalizationMode | PIC S9(9) COMP-5. Can be COMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 1062e5b6d6dSopenharmony_ci| UerrorCode | PIC S9(9) COMP-5. Can be COMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 1072e5b6d6dSopenharmony_ci| pointer(*) to object (e.g. Uconverter *) | PIC S9(9) COMP-5. Can be COMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 1082e5b6d6dSopenharmony_ci| Windows Handle | PIC S9(9) COMP-5. Can be COMP, COMP-4, or BINARY if you use the TRUNC(BIN) compiler option. | 1092e5b6d6dSopenharmony_ci 1102e5b6d6dSopenharmony_ci### Enumerations (first possibility) 1112e5b6d6dSopenharmony_ci 1122e5b6d6dSopenharmony_ciC Enumeration types do not translate very well into COBOL. There are two 1132e5b6d6dSopenharmony_cipossible ways to simulate these enumerations. 1142e5b6d6dSopenharmony_ci 1152e5b6d6dSopenharmony_ci#### C example 1162e5b6d6dSopenharmony_ci 1172e5b6d6dSopenharmony_ci```c 1182e5b6d6dSopenharmony_ci typedef enum { 1192e5b6d6dSopenharmony_ci /** No decomposition/composition. @draft ICU 1.8 */ 1202e5b6d6dSopenharmony_ci UNORM_NONE = 1, 1212e5b6d6dSopenharmony_ci /** Canonical decomposition. @draft ICU 1.8 */ 1222e5b6d6dSopenharmony_ci UNORM_NFD = 2, 1232e5b6d6dSopenharmony_ci . . . 1242e5b6d6dSopenharmony_ci } UNormalizationMode; 1252e5b6d6dSopenharmony_ci``` 1262e5b6d6dSopenharmony_ci 1272e5b6d6dSopenharmony_ci#### COBOL example 1282e5b6d6dSopenharmony_ci 1292e5b6d6dSopenharmony_ci```cobol 1302e5b6d6dSopenharmony_ci WORKING-STORAGE section. 1312e5b6d6dSopenharmony_ci *--------------- Ported from unorm.h ------------ 1322e5b6d6dSopenharmony_ci * enum UNormalizationMode { 1332e5b6d6dSopenharmony_ci 77 UNORM-NONE PIC 1342e5b6d6dSopenharmony_ci S9(9) Binary value 1. 1352e5b6d6dSopenharmony_ci 77 UNORM-NFD PIC 1362e5b6d6dSopenharmony_ci S9(9) Binary value 2. 1372e5b6d6dSopenharmony_ci … 1382e5b6d6dSopenharmony_ci``` 1392e5b6d6dSopenharmony_ci 1402e5b6d6dSopenharmony_ci### Enumerations (second possibility) 1412e5b6d6dSopenharmony_ci 1422e5b6d6dSopenharmony_ci#### C example 1432e5b6d6dSopenharmony_ci 1442e5b6d6dSopenharmony_ci```c 1452e5b6d6dSopenharmony_ci /*==== utypes.h ========*/ 1462e5b6d6dSopenharmony_ci typedef enum UErrorCode { 1472e5b6d6dSopenharmony_ci U_USING_FALLBACK_WARNING = -128, /* (not an error) */ 1482e5b6d6dSopenharmony_ci U_USING_DEFAULT_WARNING = -127, /* (not an error) */ 1492e5b6d6dSopenharmony_ci . . . 1502e5b6d6dSopenharmony_ci } UErrorCode; 1512e5b6d6dSopenharmony_ci``` 1522e5b6d6dSopenharmony_ci 1532e5b6d6dSopenharmony_ci#### COBOL example 1542e5b6d6dSopenharmony_ci 1552e5b6d6dSopenharmony_ci```cobol 1562e5b6d6dSopenharmony_ci *==== utypes.h ======== 1572e5b6d6dSopenharmony_ci 01 UerrorCode PIC S9(9) Binary value 0. 1582e5b6d6dSopenharmony_ci * A resource bundle lookup returned a fallback 1592e5b6d6dSopenharmony_ci * (not an error) 1602e5b6d6dSopenharmony_ci 88 U-USING-FALLBACK-WARNING value -128. 1612e5b6d6dSopenharmony_ci * (not an error) 1622e5b6d6dSopenharmony_ci 88 U-USING-DEFAULT-WARNING value -127. 1632e5b6d6dSopenharmony_ci . . . 1642e5b6d6dSopenharmony_ci``` 1652e5b6d6dSopenharmony_ci 1662e5b6d6dSopenharmony_ci## Call statement, calling by value or by reference 1672e5b6d6dSopenharmony_ci 1682e5b6d6dSopenharmony_ciIn general, arguments defined in C as pointers (`\*`) must be listed in the 1692e5b6d6dSopenharmony_ciCOBOL Call statement with the using by reference clause. Arguments which are not 1702e5b6d6dSopenharmony_cipointers must be transferred with the using by value clause. The exception to 1712e5b6d6dSopenharmony_cithis requirement is when an argument is a pointer which has been assigned to a 1722e5b6d6dSopenharmony_ciCOBOL variable (e.g. as a value returned by an ICU API), then it must be passed 1732e5b6d6dSopenharmony_ciby value. For instance, a pointer to a Converter passed as argument to 1742e5b6d6dSopenharmony_ciconversion APIs. 1752e5b6d6dSopenharmony_ci 1762e5b6d6dSopenharmony_ci### Conversion Declaration Examples 1772e5b6d6dSopenharmony_ci 1782e5b6d6dSopenharmony_ci#### C (API definition in \*.h file) 1792e5b6d6dSopenharmony_ci 1802e5b6d6dSopenharmony_ci```c 1812e5b6d6dSopenharmony_ci /*--------------------- UCNV.H ---------------------------*/ 1822e5b6d6dSopenharmony_ci U_CAPI int32_t U_EXPORT2 1832e5b6d6dSopenharmony_ci ucnv_toUChars(UConverter * cnv, 1842e5b6d6dSopenharmony_ci UChar * dest, 1852e5b6d6dSopenharmony_ci int32_t destCapacity, 1862e5b6d6dSopenharmony_ci const char * src, 1872e5b6d6dSopenharmony_ci int32_t srcLength, 1882e5b6d6dSopenharmony_ci UErrorCode * pErrorCode); 1892e5b6d6dSopenharmony_ci``` 1902e5b6d6dSopenharmony_ci 1912e5b6d6dSopenharmony_ci#### COBOL 1922e5b6d6dSopenharmony_ci 1932e5b6d6dSopenharmony_ci```cobol 1942e5b6d6dSopenharmony_ci PROCEDURE DIVISION. 1952e5b6d6dSopenharmony_ci Call API-Pointer using 1962e5b6d6dSopenharmony_ci by value Converter-toU-Pointer 1972e5b6d6dSopenharmony_ci by reference Unicode-Input-Buffer 1982e5b6d6dSopenharmony_ci by value destCapacity 1992e5b6d6dSopenharmony_ci by reference Input-Buffer 2002e5b6d6dSopenharmony_ci by value srcLength 2012e5b6d6dSopenharmony_ci by reference UErrorCode 2022e5b6d6dSopenharmony_ci Returning Text-Length. 2032e5b6d6dSopenharmony_ci``` 2042e5b6d6dSopenharmony_ci 2052e5b6d6dSopenharmony_ci## Call statement, Returning clause 2062e5b6d6dSopenharmony_ci 2072e5b6d6dSopenharmony_ci### Returned value is Pointer or Binary 2082e5b6d6dSopenharmony_ci 2092e5b6d6dSopenharmony_ci#### C (API definition in \*.h file) 2102e5b6d6dSopenharmony_ci 2112e5b6d6dSopenharmony_ci```c 2122e5b6d6dSopenharmony_ci U_CAPI UConverter * U_EXPORT2 2132e5b6d6dSopenharmony_ci ucnv_open(const char * converterName, 2142e5b6d6dSopenharmony_ci UErrorCode * err); 2152e5b6d6dSopenharmony_ci``` 2162e5b6d6dSopenharmony_ci 2172e5b6d6dSopenharmony_ci#### COBOL 2182e5b6d6dSopenharmony_ci 2192e5b6d6dSopenharmony_ci```cobol 2202e5b6d6dSopenharmony_ci WORKING-STORAGE section. 2212e5b6d6dSopenharmony_ci 01 Converter-Pointer PIC S9(9) BINARY. 2222e5b6d6dSopenharmony_ci PROCEDURE DIVISION 2232e5b6d6dSopenharmony_ci Move Z"iso-8859-8" to converterNameSource. 2242e5b6d6dSopenharmony_ci . . . 2252e5b6d6dSopenharmony_ci Call API-Pointer using 2262e5b6d6dSopenharmony_ci by reference converterNameSource 2272e5b6d6dSopenharmony_ci by reference UErrorCode 2282e5b6d6dSopenharmony_ci Returning Converter-Pointer. 2292e5b6d6dSopenharmony_ci``` 2302e5b6d6dSopenharmony_ci 2312e5b6d6dSopenharmony_ci### Returned value is a Pointer to string 2322e5b6d6dSopenharmony_ci 2332e5b6d6dSopenharmony_ciIf the returned value in C is a string pointer (`char \*`), then in COBOL we 2342e5b6d6dSopenharmony_cimust use a pointer to string defined in the Linkage section. 2352e5b6d6dSopenharmony_ci 2362e5b6d6dSopenharmony_ci#### C ( API definition in \*.h file) 2372e5b6d6dSopenharmony_ci 2382e5b6d6dSopenharmony_ci```c 2392e5b6d6dSopenharmony_ci U_CAPI const char * U_EXPORT2 2402e5b6d6dSopenharmony_ci ucnv_getAvailableName(int32_t n); 2412e5b6d6dSopenharmony_ci``` 2422e5b6d6dSopenharmony_ci 2432e5b6d6dSopenharmony_ci#### COBOL 2442e5b6d6dSopenharmony_ci 2452e5b6d6dSopenharmony_ci```cobol 2462e5b6d6dSopenharmony_ci DATA DIVISION. 2472e5b6d6dSopenharmony_ci WORKING-STORAGE section. 2482e5b6d6dSopenharmony_ci 01 Converter-Name-Link-Pointer Usage is Pointer. 2492e5b6d6dSopenharmony_ci LINKAGE section. 2502e5b6d6dSopenharmony_ci 01 Converter-Name-Link. 2512e5b6d6dSopenharmony_ci 03 Converter-Name-String pic X(80). 2522e5b6d6dSopenharmony_ci PROCEDURE DIVISION using Converter-Name-Link. 2532e5b6d6dSopenharmony_ci Call API-Pointer using by value Converters-Index 2542e5b6d6dSopenharmony_ci Returning Converter-Name-Link-Pointer. 2552e5b6d6dSopenharmony_ci SET Address of Converter-Name-Link 2562e5b6d6dSopenharmony_ci to Converter-Name-Link-Pointer. 2572e5b6d6dSopenharmony_ci . . . 2582e5b6d6dSopenharmony_ci Move Converter-Name-String to Debug-Value. 2592e5b6d6dSopenharmony_ci``` 2602e5b6d6dSopenharmony_ci 2612e5b6d6dSopenharmony_ci## How to invoke ICU APIs 2622e5b6d6dSopenharmony_ci 2632e5b6d6dSopenharmony_ciInter-language communication is often problematic. This is certainly the case 2642e5b6d6dSopenharmony_ciwhen calling C/C++ functions from COBOL, because of the very different roots of 2652e5b6d6dSopenharmony_cithe two languages. How to invoke the ICU APIs from a COBOL program is likely to 2662e5b6d6dSopenharmony_cidepend on the operating system and even on the specific compilers in use. The 2672e5b6d6dSopenharmony_cisection below deals with COBOL to C calls on a Windows platform. Similar 2682e5b6d6dSopenharmony_cisections should be added for other platforms. 2692e5b6d6dSopenharmony_ci 2702e5b6d6dSopenharmony_ci### Windows platforms 2712e5b6d6dSopenharmony_ci 2722e5b6d6dSopenharmony_ciThe following instructions were tested on a Windows 2000 platform, with the IBM 2732e5b6d6dSopenharmony_ciVisualAge COBOL compiler and the Microsoft Visual C/C++ compiler. 2742e5b6d6dSopenharmony_ci 2752e5b6d6dSopenharmony_ciFor Windows, ICU APIs are normally packaged as DLLs (Dynamic Load Libraries). 2762e5b6d6dSopenharmony_ciFor technical reasons, COBOL calls to C/C++ functions need to be done via 2772e5b6d6dSopenharmony_cidynamic loading of the DLLs at execution time (load on call). 2782e5b6d6dSopenharmony_ci 2792e5b6d6dSopenharmony_ciThe COBOL program must be compiled with the following compiler options: 2802e5b6d6dSopenharmony_ci 2812e5b6d6dSopenharmony_ci \* options CBL PGMNAME(MIXED) CALLINT(SYSTEM) NODYNAM 2822e5b6d6dSopenharmony_ci 2832e5b6d6dSopenharmony_ciIn order to call an ICU API, two preparation steps are needed: 2842e5b6d6dSopenharmony_ci 2852e5b6d6dSopenharmony_ci1. Load in memory the DLL which contains the API 2862e5b6d6dSopenharmony_ci 2872e5b6d6dSopenharmony_ci2. Get the address of the API 2882e5b6d6dSopenharmony_ci 2892e5b6d6dSopenharmony_ciFor performance, it is better to perform these steps once before the first call 2902e5b6d6dSopenharmony_ciand to save the returned values for future use (the sample programs get the 2912e5b6d6dSopenharmony_ciaddress of APIs for each call, for the sake of logging; production programs 2922e5b6d6dSopenharmony_cishould get the address once and reuse it 2932e5b6d6dSopenharmony_cias many times as needed). 2942e5b6d6dSopenharmony_ci 2952e5b6d6dSopenharmony_ciWhen no more APIs from a DLL are needed, the DLL should be unloaded in order to 2962e5b6d6dSopenharmony_cifree the associated memory. 2972e5b6d6dSopenharmony_ci 2982e5b6d6dSopenharmony_ci### Load DLL Into Memory 2992e5b6d6dSopenharmony_ci 3002e5b6d6dSopenharmony_ciThis is done as follows: 3012e5b6d6dSopenharmony_ci 3022e5b6d6dSopenharmony_ci Call "LoadLibraryA" using by reference DLL-Name 3032e5b6d6dSopenharmony_ci Returning DLL-Handle. 3042e5b6d6dSopenharmony_ci IF DLL-Handle = ZEROS 3052e5b6d6dSopenharmony_ci Perform error handling. . . 3062e5b6d6dSopenharmony_ci 3072e5b6d6dSopenharmony_ciReturn value: DLL Handle, defined as `PIC S9(9) BINARY` 3082e5b6d6dSopenharmony_ci 3092e5b6d6dSopenharmony_ciInput Value: DLL Name (null-terminated string) 3102e5b6d6dSopenharmony_ci 3112e5b6d6dSopenharmony_ciErrors may happen if the DLL name is not correct, or the string is not 3122e5b6d6dSopenharmony_cinull-terminated, or the DLL file is not available (in the current directory or 3132e5b6d6dSopenharmony_ciin a directory included in the PATH system variable). 3142e5b6d6dSopenharmony_ci 3152e5b6d6dSopenharmony_ci#### Get API address 3162e5b6d6dSopenharmony_ci 3172e5b6d6dSopenharmony_ciThis is done as follows: 3182e5b6d6dSopenharmony_ci 3192e5b6d6dSopenharmony_ci Call "GetProcAddress" using by value DLL-Handle 3202e5b6d6dSopenharmony_ci by reference API-Name 3212e5b6d6dSopenharmony_ci Returning API-Pointer. 3222e5b6d6dSopenharmony_ci IF API-Pointer = NULL 3232e5b6d6dSopenharmony_ci Perform error handling... 3242e5b6d6dSopenharmony_ci 3252e5b6d6dSopenharmony_ciReturn value: API address, defined as PROCEDURE-POINTER 3262e5b6d6dSopenharmony_ciInput Value: DLL Handle (returned by call to LoadLibraryA) 3272e5b6d6dSopenharmony_ciProcedure Name (null-terminated string) 3282e5b6d6dSopenharmony_ci 3292e5b6d6dSopenharmony_ciErrors may happen if the API name is not correct (remember that API names are 3302e5b6d6dSopenharmony_cicase-sensitive), or the string is not null-terminated, or the API is not 3312e5b6d6dSopenharmony_ciincluded in the specified DLL. If the API pointer is not null, the call to the 3322e5b6d6dSopenharmony_ciAPI is done with following according to the arguments and return value of the 3332e5b6d6dSopenharmony_ciAPI. 3342e5b6d6dSopenharmony_ci 3352e5b6d6dSopenharmony_ci Call API-Pointer using . . . returning . . . 3362e5b6d6dSopenharmony_ci 3372e5b6d6dSopenharmony_ciAfter calling an API, the returned error code should be checked when relevant. 3382e5b6d6dSopenharmony_ciCode to check for error conditions is illustrated in the sample programs. 3392e5b6d6dSopenharmony_ci 3402e5b6d6dSopenharmony_ci#### Unload DLL from Memory 3412e5b6d6dSopenharmony_ci 3422e5b6d6dSopenharmony_ciThis is done as follows: 3432e5b6d6dSopenharmony_ci 3442e5b6d6dSopenharmony_ci Call "FreeLibrary" using DLL-Handle. 3452e5b6d6dSopenharmony_ci 3462e5b6d6dSopenharmony_ciReturn value: none 3472e5b6d6dSopenharmony_ciInput Value: DLL Handle (returned by call to LoadLibraryA) 3482e5b6d6dSopenharmony_ci 3492e5b6d6dSopenharmony_ci## Sample Programs 3502e5b6d6dSopenharmony_ci 3512e5b6d6dSopenharmony_ciThree sample programs are supplied with this document. The sample programs were 3522e5b6d6dSopenharmony_cideveloped on and for a Windows 2000 platform. Some adaptations may be necessary 3532e5b6d6dSopenharmony_cifor other platforms 3542e5b6d6dSopenharmony_ci 3552e5b6d6dSopenharmony_ciBefore running the sample programs, you must perform the following steps: 3562e5b6d6dSopenharmony_ci 3572e5b6d6dSopenharmony_ci1. Install the version of ICU appropriate for your platform 3582e5b6d6dSopenharmony_ci 3592e5b6d6dSopenharmony_ci2. Build ICU libraries if needed (see the ICU Readme file) 3602e5b6d6dSopenharmony_ci 3612e5b6d6dSopenharmony_ci3. Make the libraries accessible (for instance on Windows systems, add the 3622e5b6d6dSopenharmony_ci directory containing the libraries to the PATH system variable) 3632e5b6d6dSopenharmony_ci 3642e5b6d6dSopenharmony_ci4. Compile the sample programs with appropriate compiler options 3652e5b6d6dSopenharmony_ci 3662e5b6d6dSopenharmony_ci5. Copy the test files to a work directory 3672e5b6d6dSopenharmony_ci 3682e5b6d6dSopenharmony_ciEach program is supplied with input test files and with a model log file. If the 3692e5b6d6dSopenharmony_cilog file that you create by running a sample program is equivalent to the model 3702e5b6d6dSopenharmony_cilog file, your setup is probably correct. 3712e5b6d6dSopenharmony_ci 3722e5b6d6dSopenharmony_ciThe three sample programs focus each on a certain ICU area of functionality: 3732e5b6d6dSopenharmony_ci 3742e5b6d6dSopenharmony_ci1. Conversion 3752e5b6d6dSopenharmony_ci 3762e5b6d6dSopenharmony_ci2. Collation 3772e5b6d6dSopenharmony_ci 3782e5b6d6dSopenharmony_ci3. Normalization 3792e5b6d6dSopenharmony_ci 3802e5b6d6dSopenharmony_ci### Conversion sample program 3812e5b6d6dSopenharmony_ci 3822e5b6d6dSopenharmony_ci * The sample program includes the following steps: 3832e5b6d6dSopenharmony_ci * - Display the names of the converters from a list of all 3842e5b6d6dSopenharmony_ci * converters contained in the alias file. 3852e5b6d6dSopenharmony_ci * - Display the current default converter name. 3862e5b6d6dSopenharmony_ci * - Set new default converter name. 3872e5b6d6dSopenharmony_ci * 3882e5b6d6dSopenharmony_ci * - Read a string from Input file "ICU_Conv_Input_8.txt" 3892e5b6d6dSopenharmony_ci * (File in UTF-8 Format) 3902e5b6d6dSopenharmony_ci * - Convert this string from UTF-8 to code page iso-8859-8 3912e5b6d6dSopenharmony_ci * - Write the result to output file "ICU_Conv_Output.txt" 3922e5b6d6dSopenharmony_ci * 3932e5b6d6dSopenharmony_ci * - Read a line from Input file "ICU_Conv_Input.txt" 3942e5b6d6dSopenharmony_ci * (File in ANSI Format, code page 862) 3952e5b6d6dSopenharmony_ci * - Convert this string from code page ibm-862 to UTF-16 3962e5b6d6dSopenharmony_ci * - Convert the resulting string from UTF-16 to code page windows-1255 3972e5b6d6dSopenharmony_ci * - Write the result to output file "ICU_ Conv_Output.txt" 3982e5b6d6dSopenharmony_ci * - Write debugging information to Display and 3992e5b6d6dSopenharmony_ci * log file "ICU_Conv_Log.txt" (File in ANSI Format) 4002e5b6d6dSopenharmony_ci * - Repeat for all lines in Input file 4012e5b6d6dSopenharmony_ci ** 4022e5b6d6dSopenharmony_ci * The following ICU APIs are used: 4032e5b6d6dSopenharmony_ci * ucnv_countAvailable 4042e5b6d6dSopenharmony_ci * ucnv_getAvailableName 4052e5b6d6dSopenharmony_ci * ucnv_getDefaultName 4062e5b6d6dSopenharmony_ci * ucnv_setDefaultName 4072e5b6d6dSopenharmony_ci * ucnv_convert 4082e5b6d6dSopenharmony_ci * ucnv_open 4092e5b6d6dSopenharmony_ci * ucnv_toUChars 4102e5b6d6dSopenharmony_ci * ucnv_fromUChars 4112e5b6d6dSopenharmony_ci * ucnv_close 4122e5b6d6dSopenharmony_ci 4132e5b6d6dSopenharmony_ciThe ucnv_xxx APIs are documented in file "UCNV.H". 4142e5b6d6dSopenharmony_ci 4152e5b6d6dSopenharmony_ci### Collation sample program 4162e5b6d6dSopenharmony_ci 4172e5b6d6dSopenharmony_ci * The sample program includes the following steps: 4182e5b6d6dSopenharmony_ci * - Read a string array from Input file "ICU_Coll_Input.txt" 4192e5b6d6dSopenharmony_ci * (file in ANSI format) 4202e5b6d6dSopenharmony_ci * - Convert string array from code page into UTF-16 format 4212e5b6d6dSopenharmony_ci * - Compare the string array into the canonical composed 4222e5b6d6dSopenharmony_ci * - Perform bubble sort of string array, according 4232e5b6d6dSopenharmony_ci * to Unicode string equivalence comparisons 4242e5b6d6dSopenharmony_ci * - Convert string array from Unicode into code page format 4252e5b6d6dSopenharmony_ci * - Write the result to output file "ICU_Coll_Output.txt" 4262e5b6d6dSopenharmony_ci * (file in ANSI format) 4272e5b6d6dSopenharmony_ci * - Write debugging information to Display and 4282e5b6d6dSopenharmony_ci * log file "ICU_Coll_Log.txt" (file in ANSI format) 4292e5b6d6dSopenharmony_ci ** 4302e5b6d6dSopenharmony_ci * The following ICU APIs are used: 4312e5b6d6dSopenharmony_ci * ucol_open 4322e5b6d6dSopenharmony_ci * ucol_strcoll 4332e5b6d6dSopenharmony_ci * ucol_close 4342e5b6d6dSopenharmony_ci * ucnv_open 4352e5b6d6dSopenharmony_ci * ucnv_toUChars 4362e5b6d6dSopenharmony_ci * ucnv_fromUChars 4372e5b6d6dSopenharmony_ci * ucnv_close 4382e5b6d6dSopenharmony_ci 4392e5b6d6dSopenharmony_ciThe ucol_xxx APIs are documented in file "UCOL.H". 4402e5b6d6dSopenharmony_ciThe ucnv_xxx APIs are documented in file "UCNV.H". 4412e5b6d6dSopenharmony_ci 4422e5b6d6dSopenharmony_ci### Normalization sample program 4432e5b6d6dSopenharmony_ci 4442e5b6d6dSopenharmony_ci * The sample includes the following steps: 4452e5b6d6dSopenharmony_ci * - Read a string from input file "ICU_NORM_Input.txt" 4462e5b6d6dSopenharmony_ci * (file in ANSI format) 4472e5b6d6dSopenharmony_ci * - Convert the string from code page into UTF-16 format 4482e5b6d6dSopenharmony_ci * - Perform quick check on the string, to determine if the 4492e5b6d6dSopenharmony_ci * string is in NFD (Canonical decomposition) 4502e5b6d6dSopenharmony_ci * normalization format. 4512e5b6d6dSopenharmony_ci * - Normalize the string into canonical composed form 4522e5b6d6dSopenharmony_ci * (FCD and decomposed) 4532e5b6d6dSopenharmony_ci * - Perform quick check on the result string, to determine 4542e5b6d6dSopenharmony_ci * if the string is in NFD normalization form 4552e5b6d6dSopenharmony_ci * - Convert the string from Unicode into the code page format 4562e5b6d6dSopenharmony_ci * - Write the result to output file "ICU_NORM_Output.txt" 4572e5b6d6dSopenharmony_ci * (file in ANSI format) 4582e5b6d6dSopenharmony_ci * - Write debugging information to Display and 4592e5b6d6dSopenharmony_ci * log file "ICU_NORM_Log.txt" (file in ANSI format) 4602e5b6d6dSopenharmony_ci ** 4612e5b6d6dSopenharmony_ci * The following ICU APIs are used: 4622e5b6d6dSopenharmony_ci * ucnv_open 4632e5b6d6dSopenharmony_ci * ucnv_toUChars 4642e5b6d6dSopenharmony_ci * unorm_normalize 4652e5b6d6dSopenharmony_ci * unorm_quickCheck 4662e5b6d6dSopenharmony_ci * ucnv_fromUChars 4672e5b6d6dSopenharmony_ci * ucnv_close 4682e5b6d6dSopenharmony_ci 4692e5b6d6dSopenharmony_ciThe unorm_xxx APIs are documented in file "UNORM.H". 4702e5b6d6dSopenharmony_ci 4712e5b6d6dSopenharmony_ciThe ucnv_xxx APIs are documented in file "UCNV.H". 472