Error calling external DLL function

pima

New Member
Hi to all,

currently i'm working on some functions implementing our dms (DocuWare) into our Progress Application. DocuWare offers two ways,
a) DLL-Functions
b) Automation

I prefered to use the dll-calls so i produced the following code exactly as the DocuWare-Documentation says:


DEFINE VARIABLE iDWToolkitSession AS INTEGER INITIAL 0 NO-UNDO.
DEFINE VARIABLE iDW4IsRunning AS INTEGER INITIAL 0 NO-UNDO.
DEFINE VARIABLE iDWResultListHandle AS INTEGER NO-UNDO.
DEFINE VARIABLE cExportedFiles AS CHARACTER NO-UNDO.
DEFINE VARIABLE iDWResult AS INTEGER NO-UNDO.

/* Procedure definitions */
PROCEDURE DWTKGetSessionHandle EXTERNAL "DWTKDLL.DLL":
DEFINE INPUT PARAMETER hParentWindow AS LONG.
DEFINE OUTPUT PARAMETER lToolkitSession AS LONG.
DEFINE RETURN PARAMETER iResult AS LONG.
END.
PROCEDURE DWTKFreeSessionHandle EXTERNAL "DWTKDLL.DLL":
DEFINE INPUT PARAMETER lToolkitSession AS LONG.
DEFINE RETURN PARAMETER iResult AS LONG.
END.
PROCEDURE DWTKIsDW4Running EXTERNAL "DWTKDLL.DLL":
DEFINE INPUT PARAMETER lToolkitSessionHandle AS LONG.
DEFINE OUTPUT PARAMETER bDW4IsRunning AS LONG.
DEFINE RETURN PARAMETER iResult AS LONG.
END.
PROCEDURE DWTKStartDocuWare EXTERNAL "DWTKDLL.DLL":
DEFINE INPUT PARAMETER plToolkitSession AS LONG.
DEFINE INPUT PARAMETER pcUsername AS CHARACTER.
DEFINE INPUT PARAMETER pcPassword AS CHARACTER.
DEFINE INPUT PARAMETER plTimeout AS LONG.
DEFINE RETURN PARAMETER iResult AS LONG.
END.

/* ------------------------------------------------------------------------------ */
RUN DWTKGetSessionHandle (INPUT CURRENT-WINDOW:HWND,
OUTPUT iDWToolkitSession,
OUTPUT iDWResult).

/* For DEBUG */
MESSAGE Integer(iDWToolkitSession) SKIP
Integer(iDWResult) VIEW-AS ALERT-BOX INFORMATION.

/* ------------------------------------------------------------------------------ */
RUN DWTKIsDW4Running (INPUT iDWToolkitSession,
OUTPUT iDW4IsRunning,
OUTPUT iDWResult).

/* For DEBUG */
MESSAGE iDW4IsRunning SKIP
iDWResult VIEW-AS ALERT-BOX INFORMATION.

/* ------------------------------------------------------------------------------ */
RUN DWTKFreeSessionHandle (INPUT iDWToolkitSession,
OUTPUT iDWResult).
/* For DEBUG */
MESSAGE iDWResult VIEW-AS ALERT-BOX INFORMATION.


After calling the function "DWTKGetSessionHandle" i get the following result:
iDWToolkitSession is a eight figures long integer (i don't know if this is the right translation).
iDWResult is 0 <- this means the function suceeded :awink:

Then calling the DWTKIsDW4Running function with the above Session-Number fails with iDWResult = -2147221503. This code means "False parameter". :confused:

I must wonder about this, because the code above worked for five or six times and since last week it doesn't work any more.

The same calls run in VB without any error. The only difference is, that the Session-Handle i get in VB is a nine figures long number.

These are my questions:
a) is there a limitation so that progress can handle only eight figures long numbers in external dll functions?
b) If it is so, is there a work around?

Progress version is currently 9.1D09 on Windows XP.


Thanks in advance for any help!!!


Marcus.
 

vice

New Member
it sounds like a problem with the used calling-conventions of the functions in the dll.

do you know which calling conventions your function use?

i know 3 different calling convention for function under windows: fastcall cdecl and stdcall. i think progress use stdcall if u don't specify it but the visual studio .net for example use cdecl as the standard calling-convention for c/c++ functions.

so if u can't look at the sourcecode of the dll you must try it out.

sample definition of a function with cdecl:

PROCEDURE MyFunction EXTERNAL "blabla.dll" CDECL PERSISTENT:
DEFINE INPUT PARAMETER A AS LONG NO-UNDO.
DEFINE INPUT PARAMETER B AS LONG NO-UNDO.
DEFINE RETURN PARAMETER iResult AS LONG NO-UNDO.
END PROCEDURE.


hope it helps
Thomas
 

pima

New Member
Hi,

after a long time i've retried to resolve this problem, and got it to work now! :D

The only thing that was wrong is, that this procedures must be made persistent.

The first procedure creates the Session-Handle but if the procedure isn't presistent, the handle will be released and so the next procedure fails....


Kommt Zeit kommt Rat......... :awink:


Marcus
 
Top