1. Eduardo Adriano
  2. PowerBuilder
  3. Saturday, 14 November 2020 22:35 PM UTC

Hi!

I m trying to verify an equipment status in a emulator program using a DLL.

PB -> DLL -> read the emulator equipament status

Using the emulator program  works well.

 

In Powerbuilder 2019 R2 - BUILD 2353

- in Global External Functions:

function string ConsultarSAT ( long al_nrSession ) Library "SAT.DLL"

 

- Calling the function:

string ls_status

ls_status = consultarSAT( 123456 )

 

I pass a number of 6 digits and return a string.

 

But, when i execute occurred the error:

Specified argument type differs from from required argument type at runtime in DLL function consultarsat.

(Invalid stack pointer on return from function call) at line ...

 

I tried many different arguments variables, but i didn't solve this

The sat.dll follow attached

I appreciate some help.

Thanks!

Eduardo

Attachments (2)
Eduardo Adriano Accepted Answer Pending Moderation
  1. Sunday, 15 November 2020 01:20 AM UTC
  2. PowerBuilder
  3. # 1

Thanks for help John!

The specification says the DLL must work in the all Windows versions.

The return type is string using pipe separator like this:

038431|08000|SAT OPERATING|002|ITS OK

Use UTF-8

The DLL made in C, but, unfortunately don't have more technical information



- My OS is Windows 10 - 64 bits

PB exe generated 32-bit platform, occurred the same problem.


For compare in Delphi declaration is:

function ConsultarSAT( SessionNumber : Longint ) : PChar ; cdecl; External 'SAT.DLL';


Regards,

Eduardo

 

Comment
  1. John Fauss
  2. Sunday, 15 November 2020 02:50 AM UTC
You will NOT be able to interface your PB application with this DLL with an external function declaration, for two reasons:

1. The SAT.DLL uses the cdecl calling convention, according to the Delphi declaration you provided. Refer to the section named "Calling Conventions" in the following URL:

http://docwiki.embarcadero.com/RADStudio/Sydney/en/Procedures_and_Functions_(Delphi)

Delphi can apparently use different calling conventions. PB can only use the stdcall calling convention.

2. The return string from the DLL function is UTF8-encoded. PB strings are UTF16LE-encoded, but external functions can also handle ANSI-encoded strings via the ALIAS FOR "entrypointname;ansi" directive in the external function declaration./

It may or may not be possible to interface with this DLL from C#, then into PB from a .NET assembly (not my area of expertise)... if so, others in the community may be able to advise you further.



  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Saturday, 14 November 2020 23:53 PM UTC
  2. PowerBuilder
  3. # 2

Hi, Eduardo - 

Does the DLL use the __stdcall, also known as WINAPI calling convention? PB can only interface with DLL's that utilize this calling convention, as this is what all Windows API functions use.

Also, is the string returned by the DLL function in Unicode (2-bytes/character) or ANSI? (Note: Edited to correct "ASCII" to "ANSI")

Do you receive this error when running the PB application from the IDE, from the compiled 32-bit app, and/or the compiled 64-bit app?

Do you have any documentation that describes the C/C++ prototype statement for the ConsultarSAT function? From your PB external function declaration, I would expect the prototype to look something like:

char * ConsultarSAT ( int argvalue );

Of course, the name of the input argument value will differ from what I've chosen. It the argument datatype is different or the return type is different, then the external function declaration in PB is probably not correct. We really need the DLL function prototype to make that determination.

Regards, John

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.