Consultor Eletrônico



Kbase P122518: The OS-GETENV function does not display extended characters properly
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   2/27/2007
Status: Unverified

FACT(s) (Environment):

OpenEdge 10.1x

SYMPTOM(s):

The OS-GETENV function displays the wrong characters

Extended characters are not displayed correctly

Using the OpenEdge Unicode client

Using -cpinternal UTF-8 for the OpenEdge client

CAUSE:

The OS-GETENV function returns the characters in the OS codepage, but the OpenEdge client does not make the conversion to -cpinternal due to a product limit. This functionality will be added in a future release of OpenEdge.

FIX:

The following sample code will do the conversion manually:
/*-----------------------------------------*/
FUNCTION GetOSEnv RETURNS CHARACTER (INPUT OSEnv AS CHARACTER) FORWARD.

MESSAGE GetOSEnv("Test")
VIEW-AS ALERT-BOX INFO BUTTONS OK.


FUNCTION GetOSEnv RETURNS CHARACTER (INPUT OSEnv AS CHARACTER):
DEFINE VARIABLE EnvVal AS CHARACTER NO-UNDO.
DEFINE VARIABLE EnvLVal AS LONGCHAR NO-UNDO.
DEFINE VARIABLE EnvMptr AS MEMPTR NO-UNDO.
DEFINE VARIABLE EnvLen AS INTEGER NO-UNDO.
DEFINE VARIABLE iCodePage AS INTEGER NO-UNDO.
DEFINE VARIABLE sCodePage AS CHARACTER NO-UNDO.

/*Get Windows codepage */
IF OPSYS = "WIN32" THEN DO:
RUN GetACP(OUTPUT iCodePage).
sCodePage = STRING(iCodePage).
END.
ELSE
sCodePage = "ISO8859-1".

EnvVal = OS-GETENV(OSEnv).
EnvLen = LENGTH(EnvVal).

SET-SIZE(EnvMptr) = EnvLen.
PUT-STRING(EnvMptr, 1, EnvLen) = EnvVal.

COPY-LOB EnvMptr TO EnvLVal CONVERT SOURCE CODEPAGE sCodePage.
COPY-LOB EnvLVal TO EnvMptr.

RETURN GET-STRING(EnvMptr, 1, EnvLen + 1).
END FUNCTION.


PROCEDURE GetACP EXTERNAL "kernel32":
DEFINE RETURN PARAMETER iCodePage AS LONG .
END PROCEDURE.
/*-----------------------------------------*/