Jump to content

WinCompareStrings

From EDM2
Revision as of 01:53, 13 May 2023 by Martini (talk | contribs) (Created page with "Compares two null-terminated strings defined using the same code page. ==Syntax== WinCompareStrings(hab, idCodepage, idCountryCode, pszString1, pszString2, ulReserved) ==P...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Compares two null-terminated strings defined using the same code page.

Syntax

WinCompareStrings(hab, idCodepage, idCountryCode, pszString1, pszString2, ulReserved)

Parameters

hab (HAB) - input
Anchor-block handle.
idCodepage (ULONG) - input
Code page identity of both strings.
If idCodepage is set to 0, the current code page of the caller is used.
idCountryCode (ULONG) - input
Country code.
If idCountryCode is set to 0, the country information for the default system country code is used.
pszString1 (PSZ) - input
String 1.
pszString2 (PSZ) - input
String 2.
ulReserved (ULONG) - input
Reserved value, should be 0.

Returns

ulResult (ULONG) - returns
Comparison result.
WCS_EQ
Strings are equal
WCS_LT
String 1 is less than string 2
WCS_GT
String 1 is greater than string 2
WCS_ERROR
Error occurred.

Errors

Possible returns from WinGetLastError

PMERR_INVALID_STRING_PARM (0x100B)
The specified string parameter is invalid.

Remarks

The first code page of either of the two ASCII code pages specified in CONFIG.SYS is used as the system default. 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. The following is the list of valid country codes:


Country

       Code 

Arabic

       785 

Australian

       61 

Belgian

       32 

Canadian-French

       2 

Danish

       45 

Finnish

       358 

French

       33 

German

       49 

Hebrew

       972 

Italian

       39 

Japanese

       81 

Korean

       82 

Latin-American

       3 

Netherlands

       31 

Norwegian

       47 

Portuguese

       351 

Simpl. Chinese

       86 

Spanish

       34 

Swedish

       46 

Swiss

       41 

Trad. Chinese

       88 

UK-English

       44 

US-English

       1 

Other country

       0

Example Code

This example compares two strings using the same code page: the first string is loaded from a resource DLL, while the second is created by the application.

#define INCL_WINCOUNTRY         /* Window Country Functions     */
#define INCL_WINWINDOWMGR       /* Window Manager Functions     */
#define INCL_DOSMODULEMGR       /* Module Manager Functions     */
#include <os2.h>

ULONG   ulResult;       /* comparison result                    */
HAB     hab;            /* anchor-block handle                  */
ULONG   idCodepage=437; /* Code page identity of both strings   */
ULONG   idCountryCode=1;/* Country code                         */
char    pszString1[10]; /* first string                         */
char    pszString2[10]; /* second string                        */
LONG    lLength;        /* length of string                     */
ULONG   idString = STRING_ID; /* String identifier              */
LONG    lBufferMax = 10;/* Size of buffer                       */
HMODULE hmodDLL;        /* Handle of the module which contains
                           the help table and help subtable
                           resources.                           */
CHAR    LoadError[100]; /* object name buffer for DosLoad       */
ULONG   rc;             /* return code                          */

/* obtain resource handle */
rc = DosLoadModule(LoadError, sizeof(LoadError), "RES.DLL",
                   &hmodDLL);

/* load string from resource */
if (rc == 0)
   lLength = WinLoadString(hab, hmodDLL, idString, lBufferMax,
                            pszString1);

/* compare strings */
if (lLength > 0)
   {
   /* set second string */
   strcpy(pszString2,"Compare");

   ulResult = WinCompareStrings(hab, idCodepage, idCountryCode,
                                pszString1, pszString2, 0);
   }

Definition

#define INCL_WINCOUNTRY /* Or use INCL_WIN, INCL_PM, */
#include <os2.h>

HAB      hab;            /*  Anchor-block handle. */
ULONG    idCodepage;     /*  Code page identity of both strings. */
ULONG    idCountryCode;  /*  Country code. */
PSZ      pszString1;     /*  String 1. */
PSZ      pszString2;     /*  String 2. */
ULONG    ulReserved;     /*  Reserved value, should be 0. */
ULONG    ulResult;       /*  Comparison result. */

ulResult = WinCompareStrings(hab, idCodepage,
             idCountryCode, pszString1, pszString2,
             ulReserved);


Related Functions

  • WinLoadString
  • WinNextChar
  • WinPrevChar
  • WinSubstituteStrings
  • WinUpper
  • WinUpperChar