1. ZBIGNIEW WABIK
  2. PowerBuilder
  3. Tuesday, 5 October 2021 12:20 PM UTC

Hello Team,

We have a problem with one function - Repaint(), which we were able to use without issues in PB 9.03, but now - after migrating the application to the new version PB 2019 R3 using the migration tool - the function execution thows errors.

It is most probably caused by types mismatch, but we cannot figure it out.

Is there now, in the new version, some background type conversion happening?

 

1. We have a C dll generated in 2010.

Unfortunately we don't have source code.

 

2. The Repaint() function declared in Local External Function

FUNCTION long Repaint (ulong handle, long swidth, long sheight, s_node a[], s_edge b[], s_edge_dod c[], int op1, int op23, int plpk, int pls, int dl) LIBRARY "graf.dll"

or

FUNCTION long Repaint (ulong handle, long swidth, long sheight, s_node a[], s_edge b[], s_edge_dod c[], int op1, int op23, int plpk, int pls, int dl) LIBRARY "graf.dll" alias for "Repainr;ansi"

or

FUNCTION long Repaint (ulong handle, long swidth, long sheight, ref s_node a[], ref s_edge b[], ref s_edge_dod c[], int op1, int op23, int plpk, int pls, int dl) LIBRARY "graf.dll" alias for "Repainr;ansi"

 

has been called with the code in a user event as below

 

Repaint (Handle(this), ll_width, ll_height, istr_node, istr_edge, istr_edge_dod, gl_node, gl_farend, gl_ports, gl_lines, displaylines)

or

Repaint (Handle(this), ll_width, ll_height, istr_node[], istr_edge[], istr_edge_dod[], gl_node, gl_farend, gl_ports, gl_lines, displaylines)

 

where for example

s_node istr_node[]

and

global type s_node from structure

long id

long x

long y

long typ

character descr1[255]

character descr2[255]

character descr3[255]

long display

long width

long height

long bitmapsize

long status

 

Other structures

s_edge istr_edge[]

s_edge_dod istr_edge_dod[]

have similar definitions.

 

The error message we get is:

"Error calling external function %s"

 

We tried using string as datatype in input instead of character, but then the error message is:

"specified argument type differs from required argument type at run time in DLL function Repaint - invalid stack pointer on return from function call at line ....)

 

3. As mentioned this dll and its functions are used in PB 9.03 application and works witout issues.

Sample screen:

 

 

4. Searched in google and Appeon community - we tried different approaches but could not find the solution for this specific problem.

We use Appeon PB 2019 R3.

Can we find in PB tools to implement this functionality - show the network schema with nodes and edges (connection between them)?

 

Any support from you will be much appreciated.

Kind regards, ZFW

ZBIGNIEW WABIK Accepted Answer Pending Moderation
  1. Wednesday, 6 October 2021 08:03 AM UTC
  2. PowerBuilder
  3. # 1

Hello Team,

Thank you for your swift reply. I was positively surprised to get it so quickly.
I will look into your suggestion and try to figure out how to fix it.
 
Problem resolved.
 
Declarations all functions in C dll library must end with a sequence:
 
alias for "name func;ansi" progma_pack(1)
 
Again, big thanks! I will reach out to you in case I have any more questions.
 
Kind regards,
Zbigniew

 

Comment
  1. John Fauss
  2. Wednesday, 6 October 2021 13:42 PM UTC
That's great news, Zbigniew! Thank you for letting us know.



If I may add a point of clarification for others that read this thread: The inclusion of the "progma_pack(1)" option on an external function declaration is NOT required when interfacing with all DLL's written in C - Zbigniew needed to use this option because the DLL his app interfaces with was created many years ago before packing on 8-byte boundaries became the standard. He did not have the DLL source code to be able to update/recompile it to utilize 8-byte packing.
  1. Helpful 2
  1. Miguel Leeuwe
  2. Wednesday, 6 October 2021 13:50 PM UTC
Very informative. Thanks John!
  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 5 October 2021 14:49 PM UTC
  2. PowerBuilder
  3. # 2

Character and String variables are now Unicode (2 bytes) so you'll need alias for "Repaint;ansi" on all the declarations. 

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

Hi, Zbigniew -

PB converted from ANSI (single-byte per character) to Unicode LE16 (two bytes per character) in version 10. The error is due to a mismatch between the amount of information being placed onto and taken off of the execution call stack.

The old, custom DLL you are using obviously is written for ANSI, and PB 2019 is passing it twice as many bytes for every element of the character arrays in the structures and any string or character argument values.

There is an option on the external function declaration (EFD) you can use to have PB convert all character-based data to/from the DLL, namely ALIAS FOR "entry_point_name;ansi". I see in the three EFD's you posted in point 2 that this conversion clause was included for the second and third EFD, but not in the first one. I think you need to add the ALIAS FOR "Repaint;ansi" clause to the first EFD.

This clause in an EFD is needed if any ANSI character/string data needs to be passed, including in any structures. It is not needed if only numeric data types are passed.

I also note that the entry point name in the second and third EFD's is "Repainr:ansi", not "Repaint:ansi". Is this a typo?

One other thing: If the DLL is expecting the memory layout of members of a structure to be single-byte aligned, you may also need to include "PROGMA_PACK(1)" in the EFD to change the default packing from 8-byte alignment to single-byte. Without knowing the options for the DLL entry points and compile options, I can't say definitely this is part of problem... but it's a possibility.

I know you do not have the DLL source code, but your best long-term option is to create a new custom DLL -OR- rewrite the functionality in C#, as PB 2019 has the capability to interface with C#.

Best regards, John

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Tuesday, 5 October 2021 13:21 PM UTC
  2. PowerBuilder
  3. # 4

Maybe the character variables are the problem. In PB 2019 it is a unicode character, in PB 9 it was ansi.

You could try to change to byte datatype.

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.