WinPrevChar
Appearance
This function moves to the previous character in a string.
Syntax
WinPrevChar(hab, ulCodepage, ulCountry, pszStart, pszCurrentChar)
Parameters
- hab (HAB) - Input
- Anchor-block handle.
- ulCodepage (ULONG) - Input
- Code page.
- If a non-existent code page is specified for ulCodepage, the code page specified by the queue associated with the calling thread is used.
- ulCountry (ULONG) - Input
- Reserved value, must be 0.
- pszStart (PSZ) - Input
- Character string that contains pszCurrentChar.
- pszCurrentChar (PSZ) - Input
- Current character.
Returns
- pszPrevChar (PSZ) - returns
- Previous character.
- The previous character, or the first character if pszCurrentChar is the first character of pszStart.
Remarks
This function handles DBCS strings.
The following is the list of valid code pages:
- 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:
- 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:
- 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
Errors
Possible returns from WinGetLastError:
- PMERR_INV_CODEPAGE (0x2052) - An invalid code-page was specified. This error can be obtained if using double-byte character set only.
- PMERR_INVALID_STRING_PARM (0x100B) - The specified string parameter is invalid.
Example Code
This example uses WinPrevChar to return a pointer to the previous character in a string.
#define INCL_DOSNLS #define INCL_WINCOUNTRY #define CURRENT_COUNTRY 0 #include <OS2.H> #include <stdio.h> // Assume HIUSHORT is defined if used #ifndef HIUSHORT #define HIUSHORT(l) ((USHORT)((l) >> 16)) #endif int main() // Changed void main() to int main() { HAB hab = NULLHANDLE; /* Anchor-block handle - NOTE: Needs proper initialization via WinInitialize */ char string[] = "ABCDEFGHIJ"; char *ptoE = &string[4]; /* Pointer to 'E' */ char *ptoD; ULONG CodePage; /* List returned */ ULONG DataLength; /* Length of list returned */ COUNTRYCODE Country; COUNTRYINFO CtryBuffer; Country.country = CURRENT_COUNTRY; /* NOTE: Error checking for Dos calls is omitted for brevity */ DosQueryCp( sizeof(CodePage), /* Size of buffer, may need adjustment if expecting list */ &CodePage, /* Get code page identifier(s) */ &DataLength); /* First WORD contains the codepage - NOTE: Original logic; DosQueryCp returns a list, HIUSHORT might be wrong here */ Country.codepage = (ULONG)HIUSHORT(CodePage); /* Get the corresponding country code */ DosQueryCtryInfo( sizeof(CtryBuffer), /* Length of data area */ &Country, /* Input data structure */ &CtryBuffer, /* Data area to be filled */ &DataLength); /* Length of data */ /* A pointer should be returned to character 'D' in the string */ ptoD = WinPrevChar(hab, (ULONG)CodePage, /* NOTE: Using possibly incorrect CodePage value from HIUSHORT */ (ULONG)CtryBuffer.country, (PSZ)string, ptoE); /* Pointer to character 'E' */ /* Original example only had printf(ptoE); which would print from 'E' onwards */ /* Example showing pointers returned: */ printf("Pointer to previous char (ptoD): %p, Pointer to current char (ptoE): %p\n", ptoD, ptoE); // WinTerminate(hab); // Should be called if WinInitialize was used return 0; }