Consultor Eletrônico



Kbase 15054: Using Windows API 'GetPrivateProfileString' for ini files
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/05/1998
Using Windows API 'GetPrivateProfileString' for ini files

DRAFT COPY - Currently under review and edit.

INTRODUCTION:
=============

The following describes the syntax to access the Windows API function,
'GetPrivateProfileString' to access Windows .ini files from a Progress
7 session.
WHY YOU NEED TO KNOW THIS:
===========================

Windows .ini files contain application specific parameters, such as
inital startup options, available fonts and printer definitions.
Reading these parameters from a Progress application allows the user
to access Windows wide information such as the default printer current
ly selected.

PROCEDURAL APPROACH:
====================

The following is an extract from the WIN.INI file:

[windows]
borderWidth=3
CursorBlinkRate=530
DoubleClickSpeed=452
Programs=com exe bat pif
device=HP LaserJet 4/4M,HPPCL5E,LPT1:

We are going to use the API GetPrivateProfileString to read the
'device' entry, this entry is useful when calling the Progress Report
Builder Engine to overwrite the default .prl values:
RB-PRINTER-NAME and RB-PRINTER-PORT

1) Define the DLL entry point to the API

define variable v-pointer as memptr no-undo.
define variable v-return as integer no-undo.

set-size(v-pointer) = 128. /* Im guessing that the maximum returned
character string will be less than
128 character */

put-string(v-pointer,1) = fill(chr(0),127).

procedure GetPrivateProfileString external "kernel.dll":
define input parameter p-section as character. /*sectionname]*/
define input parameter p-entry as character. /*entry= */
define input parameter p-default as character. /*default value*/
define input-output parameter p-pointer as memptr. /*pointer*/
define input parameter p-size as short. /*size of retuned char*/
define input parameter p-inifile as character. /*ini filename*/
define return parameter p-return as short.
end procedure.

The calling syntax is:

run GetPrivateProfileString(input "windows",
input "device",
input "",
input-output v-pointer,
input 128,
input "WIN.INI",
output v-return).

message get-string(v-pointer, 1)
view-as alert-box error buttons ok.

I perform no error processing, but it may be wise to verify that
v-return is not zero and is less than 128 as this would indicate that
the returned string length may be greater than the size of memory
we allocated for it.

The returned string is "HP LaserJet 4/4M,HPPCL5E,LPT1:", which is a
comma separated description of the default printer, this string will
need to be stripped down if the information is to be passed to the
Report Builder Engine.
assign RB-PRINTER-NAME="HP LaserJet 4/4M"
RB-PRINTER-PORT="LPT1:".

Progress Software Technical Support Note # 15054