Question Can't get DLL call to work... help needed and rewarded

HarryHorse

New Member
Hi,

I have an external DLL that I need to call from Progress 4GL. It's my first attempt on DLL calls; I gave it a shot after reading the Shared Library and DLL Support chapters in the documentation.
However, everytime I run my test program, Progress crashes when I call the DLL. I try this out on 10.0B character client on XP, 32bit. I hope it will eventually also work on 64bit Win7.

Can anyone help? I have attached a zipfile with the DLL, the documentation and my test program. This code is for a voluntary project of mine; however it annoys me so much that I am willing to reward ($100) the first one who can help me out getting this to work.

Thanks a lot,

Onno


The function I need to call (in dds.dll) looks like:

extern "C" __declspec(dllimport) int __stdcall SolveBoard(struct deal, int target,
int solutions, int mode, struct futureTricks *futp, int threadIndex);

and I came up with:
Code:
{ddsfunc.i}
 
PROCEDURE SolveBoard EXTERNAL "dds.dll" STDCALL:
  DEFINE INPUT        PARAMETER deal        AS MEMPTR NO-UNDO. /* struct  */
  DEFINE INPUT        PARAMETER target      AS LONG  NO-UNDO. /* int    */
  DEFINE INPUT        PARAMETER solutions  AS LONG  NO-UNDO. /* int    */
  DEFINE INPUT        PARAMETER mode        AS LONG  NO-UNDO. /* int    */
  DEFINE      OUTPUT PARAMETER futp        AS MEMPTR NO-UNDO. /* *struct */
  DEFINE INPUT        PARAMETER threadindex AS LONG  NO-UNDO. /* int    */
  DEFINE RETURN      PARAMETER stat        AS LONG  NO-UNDO. /* int    */
END PROCEDURE. /* SolveBoard */
 
 
DEFINE VARIABLE iTarget      AS INTEGER INIT -1 NO-UNDO.
DEFINE VARIABLE iSolutions  AS INTEGER INIT 1  NO-UNDO.
DEFINE VARIABLE iMode        AS INTEGER INIT 1  NO-UNDO.
DEFINE VARIABLE iThreadIndex AS INTEGER INIT 1  NO-UNDO.
DEFINE VARIABLE iStat        AS INTEGER        NO-UNDO.
DEFINE VARIABLE mDeal        AS MEMPTR          NO-UNDO.
DEFINE VARIABLE mFut        AS MEMPTR          NO-UNDO.
DEFINE VARIABLE iTrump      AS INTEGER INIT 0  NO-UNDO. /* SPADES */
DEFINE VARIABLE iFirst      AS INTEGER INIT 0  NO-UNDO. /* NORTH */
 
SET-SIZE(mDeal) = 4 + 4 + 12 + 12 + 64.
PUT-LONG(mDeal, 1) = iTrump.
PUT-LONG(mDeal, 5) = iFirst.
PUT-LONG(mDeal, 9) = 0.                    /* CurrentTrickSuit[1] */
PUT-LONG(mDeal,13) = 0.                    /* CurrentTrickSuit[2] */
PUT-LONG(mDeal,17) = 0.                    /* CurrentTrickSuit[3] */
PUT-LONG(mDeal,21) = 0.                    /* CurrentTrickRank[1] */
PUT-LONG(mDeal,25) = 0.                    /* CurrentTrickRank[2] */
PUT-LONG(mDeal,29) = 0.                    /* CurrentTrickRank[3] */
PUT-LONG(mDeal,33) = HandToBits("KQ853").
PUT-LONG(mDeal,37) = HandToBits("8").
PUT-LONG(mDeal,41) = HandToBits("AKJ").
PUT-LONG(mDeal,45) = HandToBits("KJ85").
 
PUT-LONG(mDeal,49) = HandToBits("AJ72").
PUT-LONG(mDeal,53) = HandToBits("KJ72").
PUT-LONG(mDeal,57) = HandToBits("94").
PUT-LONG(mDeal,61) = HandToBits("QT6").
 
PUT-LONG(mDeal,65) = HandToBits("9").
PUT-LONG(mDeal,69) = HandToBits("AQ6").
PUT-LONG(mDeal,73) = HandToBits("QT753").
PUT-LONG(mDeal,77) = HandToBits("9732").
 
PUT-LONG(mDeal,81) = HandToBits("T64").
PUT-LONG(mDeal,85) = HandToBits("T9543").
PUT-LONG(mDeal,89) = HandToBits("862").
PUT-LONG(mDeal,93) = HandToBits("A4").
 
SET-SIZE(mFut) = 4 + 4 + 52 + 52 + 52 + 52.
RUN SolveBoard(INPUT  mDeal,
              INPUT  iTarget,
              INPUT  iSolutions,
              INPUT  iMode,
              OUTPUT mFut,
              INPUT  iThreadIndex,
              OUTPUT iStat).
DISPLAY iStat.
SET-SIZE(mDeal) = 0.
SET-SIZE(mFut) = 0.
 

Attachments

  • ddstry.zip
    83.4 KB · Views: 10

medu

Member
maybe the futureTricks structure is allocated inside the DLL, you can try to use LONG instead of MEMPTR for that parameter and then use SET-POINTER-VALUE to get the actual content from that location... the memory need to be freed afterwards, you might crash the session if attempt to do it from 4gl, there might be a 'clean-up' function in the DLL

... or allocate the structure yourself and send only the pointer as LONG (GET-POINTER-VALUE)
 
Top