Kbase 15665: How to access a pointer from a MEMPTR structure ( DLL )
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/10/1998 |
|
How to access a pointer from a MEMPTR structure ( DLL )
HOW TO RETRIEVE A POINTER FROM A STRUCTURE
------------------------------------------
A DLL may return a MEMPTR that points to a C structure.
In many cases, you can use the GET-SHORT, GET-BYTE, GET-LONG
routines to access the information you want
from that structure.
What if your C structure contains a pointer? There are two
steps you must take to access this pointer as a MEMPTR.
STEP 1. Use GET-LONG to access the LONG value (pointer)
that is embedded in your structure.
STEP 2. In version 8.0B and above, you can use the
SET-POINTER-VALUE to convert the LONG into a MEMPTR.
At this point you can use the regular GET- routines
to access the info pointed to by this MEMPTR.
You are done.
In version 8.0A and below, the SET-POINTER-VALUE
does not exist. You must use the DLL long2ptr
to convert the LONG into a MEMPTR.
HOW TO ACCESS THE LONG2PTR.DLL
------------------------------
The long2ptr DLL is provided by Progress and can be found
in the pub/dll directory on PSCGATE. Please see the kbase
entry titled 'Steps for using ftp between Bedford and the
customer site' (entry 13869) for exact steps on how to
access the pub directory on pscgate using ftp.
Once you have access to the pub directory, please cd to the
dll directory to access the following files:
long2ptr.zip -- zip file that contains the
long2ptr.dll
l2p.p -- Progress 4gl source
file showing how to use
the long2ptr.dll
HOW TO USE LONG2PTR.DLL (AN EXAMPLE)
------------------------------------
The l2p.p 4gl source is included in this kbase entry
as an example of how to use long2ptr.zip--please see below:
/*
* Program Name: long2ptr.p
* Description : Shows how to use the long2ptr Windows DLL to extract
* a pointer from a structure.
* Author : Gerry Seidl
* Created on : 9/22/95
* Notes : This procedure creates a structure containing two
* pointers to character data and shows you how to obtain
* a pointer from the structure into a memptr variable.
* This procedure is particuarly useful when all you have
* is a pointer to a structure and you need to access data
* which is pointed to by a pointer in the structure.
* PROGRESS does not currently give you a way to get this
* pointer any other way.
*/
DEFINE VARIABLE p AS MEMPTR. /* will receive pointer from DLL */
DEFINE VARIABLE cstruct AS MEMPTR. /* ptr to structure containing a,b
DEFINE VARIABLE a AS MEMPTR. /* char ptr */
DEFINE VARIABLE b AS MEMPTR. /* char ptr */
DEFINE VARIABLE longval AS INTEGER NO-UNDO.
DEFINE VARIABLE str AS CHARACTER NO-UNDO.
SET-SIZE(p) = 4.
SET-SIZE(a) = 49.
PUT-STRING(a,1) = "This char data is pointed to by 'a' (cstruct->a)".
SET-SIZE(b) = 49.
PUT-STRING(b,1) = "This char data is pointed to by 'b' (cstruct->b)".
/* Structure containing pointers
struct cstruct {
char *a;
char *b;
};
*/
SET-SIZE(cstruct) = 8.
PUT-LONG(cstruct,1) = GET-POINTER-VALUE(a).
PUT-LONG(cstruct,5) = GET-POINTER-VALUE(b).
/* get long value of *b */
ASSIGN longval = GET-LONG(cstruct,5).
/* use DLL to cast long to ptr */
RUN LONG2PTR (INPUT longval, OUTPUT p).
/* retrieve value pointed to by b */
ASSIGN str = GET-STRING(p,1).
MESSAGE str VIEW-AS ALERT-BOX INFORMATION.
/* Free memory allocated my memptrs */
SET-SIZE(a) = 0.
SET-SIZE(p) = 0.
SET-SIZE(cstruct) = 0.
SET-SIZE(b) = 0.
RETURN.
/* DLL internal procedure defining entry point LONG2PTR */
PROCEDURE LONG2PTR EXTERNAL "long2ptr.dll" ORDINAL 1 CDECL:
DEFINE INPUT PARAMETER l AS LONG.
DEFINE RETURN PARAMETER p AS MEMPTR.
END.
Progress Software Technical Support Note # 15665