Problem of MEMPTR returned by DLL

DevTeam

Member
Hi there,

Quick explanation : my program calls a DLL routine which returns a string-containing memptr (corresponding to a "char *" in the C++ program).

Here's a sample of the DLL code :
Code:
char * sessionJava::reception() {
    [...]
    result = recv (ma_socket, buffer, taille, 0);
    std::string var;
    for(int i = 0; i < taille; i++) {
       var += buffer[i];
    }
    delete[] buffer;
    return (char *)var.c_str();
}
and here's the Progress code :
Code:
SET-SIZE(ptr) = 0.
SET-SIZE(ptr) = 65000.
RUN reception(OUTPUT ptr).
ASSIGN maChaine = GET-STRING(ptr, 1).


PROCEDURE reception EXTERNAL "/lib/maDLL.dll" CDECL PERSISTENT:
  DEFINE RETURN PARAMETER retour AS MEMPTR.
END PROCEDURE.

The Progress program crashes on the "get-string" instruction when the char * points to a string > 16355 Bytes...

Any idea about the reason of this crash ? Could this be a limit of the MEMPTR type (which I expected to be unlimited) ? A wrongly-set session parameter ?

Any help is welcome. Thanks in advance.

Julien
 

FrancoisL

Member
It probably your CHAR variable that hits it maximum number of character.

A CHAR variable is not big enough to hold 65000 chars.
 

DevTeam

Member
Hi François,

I know the CHAR data type is limited to 32k.

But the GET-STRING function reads the MEMPTR until a NULL value is returned... So when the MEMPTR contains only 20kBytes, the GET-STRING should get those bytes, feed the CHAR variable and not crash, shouldn't it ?
 

doreynie

Member
Test the size of ptr with get-size(ptr). Only if it is bigger than 0, try following : message get-string(ptr,1,5) --> get the first 5 bytes of your memptr (only if size allows this, if size is only 4 byte, then get-string(ptr,1,4)...

To assure you have something in the ptr.
 

DevTeam

Member
Test the size of ptr with get-size(ptr). Only if it is bigger than 0, try following : message get-string(ptr,1,5) --> get the first 5 bytes of your memptr (only if size allows this, if size is only 4 byte, then get-string(ptr,1,4)...
To assure you have something in the ptr.
What about short strings, say 20 bytes ?


Whatever I got from the DLL (10 characters or 20000 characters), the Get-Size(ptr) retrieved 0...... whereas it worked perfectly for strings variables < 16000 characters !!! :confused:


I sent a mail to the Progress support, and it turns out my DLL is to be blamed... Indeed, it returns a variable pointer to my 4GL program, but the variable is deleted when I get out the DLL method... So the fact I can get ~16000 characters may be a coincidence (data remaining in memory...)

It may be necessary to get my "C++ for dummies" book out of my shelves...
 
Top