1. Gimmy Susan
  2. PowerBuilder
  3. Friday, 30 March 2018 18:44 PM UTC
Hello to all
I have a question from Noob.
I'm studying how to create a DLL in Visual Studio C # and invoke it in Powerbuilder.
Unfortunately I have an error:
Bad runtime function reference ....
What am I doing wrong?
Thanks for the reply.

I copy under the code

Gimmy

 

 

 

VS.C#

====

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AMGenerale
{
    public class AMUtility
    {
        public int AMSomma(int _n1, int _n2)
        {
            int totale = _n1 + _n2;
            return totale;
        }
    }
}

 

 

Powerbuilder 2017R2

==================

- Global External Function: FUNCTION integer AMSomma(int a1, int a2) library 'AMgenerale.dll'

- Code: commanButton.Event

int  a1, a2, a3
string s3
a1 = 1
a2 = 2
a3=AMSomma(a1, a2)
s3 = string(a3)
messagebox('', s3)

 

Accepted Answer
Michael Kramer Accepted Answer Pending Moderation
  1. Friday, 30 March 2018 20:05 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi,

Two issues

  1. C# - so you are generating a .NET assembly.
    ​Unfortunately external function in PowerBuilder requires WINAPI (_stdcall) format which is a "standard Windows" DLL format.
    ​See PowerBuilder Help > PowerScript Reference > PowerScript Topics > Declarations > Declaring external functions > Defining source for external functions.
  2. Datatype "int" - PowerBuilder defines "int" as 16-bit integer but C# defines "int" as 32.bit integer.
PowerBuilder Integers C# / C++ Integers

byte

byte
int short
uint ushort
long int
ulong uint
longlong long

 

You can use OLEObject in PowerBuilder to interface towards C# class in a .NET assembly using "COM Callable Wrapper" as the interop technology.

 

HTH /Michael

Comment
There are no comments made yet.
Gimmy Susan Accepted Answer Pending Moderation
  1. Saturday, 31 March 2018 15:08 PM UTC
  2. PowerBuilder
  3. # 1

Hi michael.

now i have understand

 

"You can't call methods of a C# type directly like you can with "normal" (native) DLL exported functions"

Native C++ code might be an option to explore, along with C# .NET.     As I recall, to work with native C++ in Visual Studio, one selects "Other Languages/Visual C++/Win32" template ... is that correct ?   I will very llikely try both methods.

 

 

Is it Right ?

Comment
  1. Roland Smith
  2. Sunday, 1 April 2018 06:20 AM UTC
That is correct.



Define the functions like this:



int WINAPI AMSomma (int a1, int a2) {



}



The function also has to be exported. There are two ways to do that. One is to add a .def file to the project and the other is to add 

__declspec(dllexport) to the function definition.



The easiest way to do that would be to add this:





#define DllExport __declspec( dllexport )



Then define your function like this:



DLLExport int WINAPI AMSomma (int a1, int a2) {



}

  1. Helpful
  1. Michael Kramer
  2. Sunday, 1 April 2018 20:24 PM UTC
Hi Roland,



Thanks for helping me help Gimmy. Easter with family is keeping my busy.



/Michael

  1. Helpful
  1. Rodolfo Reyes
  2. Monday, 2 April 2018 19:35 PM UTC
  1. Helpful 1
There are no comments made yet.
Gimmy Susan Accepted Answer Pending Moderation
  1. Saturday, 31 March 2018 14:57 PM UTC
  2. PowerBuilder
  3. # 2

Hi Michael

Thx for replay.

I check the manual: https://www.appeon.com/support/documents/appeon_online_help/pb2017r2/powerscript_reference/ch03s04.html#d0e3758, but i have not understand where is the problem.

I create a VS program for consuming the DLL and it works fine.

I do not understand why PB do not work.

Gimmy

 

P.s.

i correct the data type

 

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.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.