1. André Monz
  2. PowerBuilder
  3. Tuesday, 22 October 2019 12:22 PM UTC

Hello all,

i'm have some trouble with the implementation of a third party DLL.
According to the Author of the DLL,it is a 'C shared library'.
I'm not familiar with c/c#.
Every call to a function witch have parameters ends with the runtime error
'Specified argument type differs from required argument type at runtime in DLL function
getmaxnumber. (invalid stack pointer on return from function call at line ..........'

For Example,
definition from the manual (c-Header File):
short int getMaxNumber(unsigned long int *maxNumber);

My Local extarnal Function in Powerbuilder
function Integer getMaxNumber(ref ulong maxNumber)  LIBRARY "external.dll" ALIAS FOR "getMaxNumber"

Powerscript:


integer li_Ret=0
ulong lul_var=0
li_ret=getMaxNumber(lul_var)
return lul_var

Any clue, what im doing wrong?

Any help would be appreciated

Regards,

André

 

 

 

 

 

 

 

Accepted Answer
Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 22 October 2019 16:55 PM UTC
  2. PowerBuilder
  3. # Permalink

Also, the asterisk in front of the argument name indicates that it is an array.

The declaration should be:

function Integer getMaxNumber(ref ulong maxNumber[])  LIBRARY "external.dll" ALIAS FOR "getMaxNumber"

It won't work until the author recompiles it with WINAPI. The way it is now, only C/C++ apps can call it.

If the author is unable or unwilling, someone will have to write a 'wrapper DLL' that uses WINAPI and has functions that just call the function in the first dll.

Comment
There are no comments made yet.
André Monz Accepted Answer Pending Moderation
  1. Tuesday, 22 October 2019 22:33 PM UTC
  2. PowerBuilder
  3. # 1

Hello,

first, thank you all for your replies.

@Michael Unfortunatley longlong won't help.

The dll is from the austria company a-trust.at.
It should help to fulfill state requirements to cash registers here in Germany.
Access to the dll/documentation is only possible after a partnership agreement with them.
Since Its copyrighted, i cant't upload the dll neither the documentation.

@Roland Special thanks to you, for your detailed explanation.
              With that, i hope a-trust can help.

 

Best Regards
André

 

   
              

 

 

 

 

 

 

 

 

Comment
  1. Michael Kramer
  2. Tuesday, 22 October 2019 23:15 PM UTC
Hi André, I trust Roland's tips on datatype and calling conventions show the path to success. He has done far more language interop than I have. I try to push PowerScript to its limits to remain in PowerScript as much as possible. Which is slightly off topic for this issue.v Good luck! /Michael
  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 22 October 2019 16:50 PM UTC
  2. PowerBuilder
  3. # 2

Your C/C++ functions should be defined like this:

return-datatype WINAPI function-name ( arguments ) {

}

 

See this:

https://stackoverflow.com/questions/2348442/what-does-winapi-in-main-function-mean

 

To determine the proper datatype on the PowerBuilder side, use this page to see what the C/C++ datatypes mean:

https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types?redirectedfrom=MSDN

 

A 'short int' is a 16-bit signed number which in PB is integer.

An unsigned long would be a 32-bit unsigned number which in PB is unsignedlong.

 

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 22 October 2019 13:42 PM UTC
  2. PowerBuilder
  3. # 3

Hi, Andre -

The error is trying to let you know that the called (external) function did not pull or push the expected amount of parameter data from the call stack when it returned execution to PB. One way this can occur is if the PB datatype(s) do not match the DLL's specifications.

However, an external function that interfaces with PB must follow the WinAPI calling conventions, so the DLL functions in the C/C++ source code have to be declared to use the _stdcall calling interface. Refer to Chapter 23, Section 1 in PB's Application Techniques documentation. If the author of the DLL has not done this, PB cannot call it successfully.

Can you provide a link to the third-party's online documentation for this DLL, if it is available online?

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 22 October 2019 13:40 PM UTC
  2. PowerBuilder
  3. # 4

Can you upload the DLL so we can give it a try?

Comment
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Tuesday, 22 October 2019 13:20 PM UTC
  2. PowerBuilder
  3. # 5

Hi,

I believe "long" in C is shorthand for int64 = longlong in PowerScript.

In any case, PowerBuilder's External function calls follow "Pascal calling conventions" which is the common convention for Windows DLLs. You should confirm that the DLL in question follows this convention if longlong doesn't fix your issue.

HTH /Michael

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.