Consultor Eletrônico



Kbase 17122: How to Call WIN32 API Function: GetSystemDirectory
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/05/1998
How to Call WIN32 API Function: GetSystemDirectory

DISCLAIMER:
===========
The code example in this knowledgebase is for informational purposes
only. If you have specific questions about which API calls would be
best suited to your design goals, please consult your Microsoft
documentation.

INTRODUCTION:
=============
The following sample code shows how to call the Win32 API function
called GetSystemDirectory. This function returns the name of the
Windows system directory. This is the directory where such things
as fonts, icon libraries, and dynamic link libraries are stored.

This code has been tested on Windows NT 4.0 Workstation only.


DEFINE VARIABLE chrDirectoryName AS CHARACTER NO-UNDO FORMAT "X(256)".
DEFINE VARIABLE intSysPathCount AS INTEGER NO-UNDO INITIAL 256.
DEFINE VARIABLE intResult AS INTEGER NO-UNDO.
DEFINE VARIABLE ptrToString AS MEMPTR NO-UNDO.

PROCEDURE GetSystemDirectoryA EXTERNAL "KERNEL32.DLL":
DEFINE OUTPUT PARAMETER ptrToString AS MEMPTR.
DEFINE INPUT PARAMETER intSysPathCount AS LONG.
DEFINE RETURN PARAMETER intResult AS LONG.
END PROCEDURE.

SET-SIZE(ptrToString) = 256.

RUN GetSystemDirectoryA (OUTPUT ptrToString,
INPUT intSysPathCount,
OUTPUT intResult).

ASSIGN chrDirectoryName = GET-STRING(ptrToString,1).

IF intResult = 0 THEN
MESSAGE "Function call failed, not sure why" VIEW-AS ALERT-BOX.
ELSE
IF intResult = LENGTH(chrDirectoryName) THEN
MESSAGE chrDirectoryName VIEW-AS ALERT-BOX.
ELSE
MESSAGE "Buffer size is too small. Must be at least " +
STRING(intResult) VIEW-AS ALERT-BOX.

SET-SIZE(ptrToString) = 0.

Progress Software Technical Support Note # 17122