Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Call C# assembly and its method in PowerBuilder

0.00/5 (No votes)
18 Aug 2013 3  
Call C# class and its method in PowerBuilder 11.

Introduction 

Call method from C# class file/DLL in PowerBuilder 11.

Using the code 

If you use .NET target of PB 11, you can call a C# class using a .NET assembly. 

C# class DLL:

-------------------------------------------------------------------------------------

using System;
using System.Collections.Generic; 
using System.Text; 
using System.Runtime.InteropServices; 

namespace ClassLibrary1 
{
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class Calc
    {
        public int Add(int x, int y)
        { 
            return x + y; 
        } 
        public int Sub(int x, int y)
        { 
            return x - y; 
        } 
    } 
} 

-------------------------------------------------------------------------------------

In the .NET Windows form target, define the DLL above as a .NET assembly. Now you can call the DLL. Here is the PowerBuilder script:

------------------------------------------------------------------------------------- 
long i,j,k 
i = 5 
j = 4 
 #IF Defined PBDOTNET Then 
         ClassLibrary1.Calc l_ClassLibrary1  
     l_ClassLibrary1 = create ClassLibrary1.Calc 
          k =                 l_ClassLibrary1.Add( i,j) 
 #END IF 
 messagebox("Add( i,j)",string(k)) 
-------------------------------------------------------------------------------------

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here