1. Yasir Masood
  2. PowerBuilder
  3. Monday, 9 January 2023 03:44 AM UTC

Hi,

I have a question about using a C# DLL in PB. We purchased a third-party DLL that was written in C with a VB 6 wrapper. I was able to use the VB 6 DLL without any issue. The declaration was as follows

SUBROUTINE calculate (double a, double b, long c, REF double d, REF long I) LIBRARY "vb32.dll" ALIAS FOR "calculate;Ansi"

Now our company have decided to use a C# wrapper instead of VB 6. When I declare the C# DLL, I get a syntax error.

private static extern void calculate (double a, double b, long c, ref double d, ref long l) LIBRARY "x32.dll" ALIAS FOR "calculate";

I am using PB 2017 R3 Build 1858.

I would appreciate any help.

Thank you

René Ullrich Accepted Answer Pending Moderation
  1. Monday, 9 January 2023 08:21 AM UTC
  2. PowerBuilder
  3. # 1

private static extern void calculate (double a, double b, long c, ref double d, ref long l) LIBRARY "x32.dll" ALIAS FOR "calculate";

This does not look like PB code nor C# code?

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 9 January 2023 15:04 PM UTC
  2. PowerBuilder
  3. # 2

You can call a regular C DLL function directly from PB without a wrapper.

"static extern void" are regular C terminology, the rest is a valid PB external function declaration.

Comment
  1. Yasir Masood
  2. Tuesday, 10 January 2023 04:03 AM UTC
The original code was written in C but there was no C DLL. We only got it with a VB DLL.



I understand that we can create C DLL now but since we will be porting the app to .NET, they want to use a C# DLL
  1. Helpful 1
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 9 January 2023 12:33 PM UTC
  2. PowerBuilder
  3. # 3

Hi Yasir;

  For interacting directly with  C# .Net assemblies in newer Appeon PB versions, you can now use the "DotNetObject" object class. However, you have to use the C# "importer" tool, as follows:

https://docs.appeon.com/pb2022/application_techniques/Importing_CSharp_assembly.html

HTH

Regards ... Chris 

Comment
There are no comments made yet.
Yasir Masood Accepted Answer Pending Moderation
  1. Monday, 9 January 2023 17:58 PM UTC
  2. PowerBuilder
  3. # 4

Thank you Chris. I will try this

Comment
There are no comments made yet.
Yasir Masood Accepted Answer Pending Moderation
  1. Monday, 9 January 2023 17:59 PM UTC
  2. PowerBuilder
  3. # 5

What version of PB do I need for this to work?

Comment
  1. Roland Smith
  2. Monday, 9 January 2023 19:26 PM UTC
The original post says they purchased a C dll that came with a VB6 wrapper. They can call into a C dll directly using an external function declaration. Using C# is a totally unnecessary complication.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Monday, 9 January 2023 19:43 PM UTC
Hi Roland;

The original post title was "Calling C# DLL". ;-)

Regards... Chris
  1. Helpful
  1. Roland Smith
  2. Monday, 9 January 2023 20:11 PM UTC
He wants to try C# because he couldn't get it to work by calling the VB6 wrapper. If the DLL is regular C, he doesn't need C# or VB6.
  1. Helpful 1
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.