1. Christophe Feyte
  2. PowerBuilder
  3. Thursday, 6 August 2020 09:29 AM UTC

Hello,

We build a C# dll to use the SendInBlue's API (https://www.sendinblue.com/)
We want to call the function from PowerBuilder 2019 build 2170.
We pass as argument a string array that contains a list of recipients.
When we check the contents of the array in the function of the DLL, it contains only the first row, whereas we have an array that contains 4 records.

Here is how we declared the function in PB :
Function String SendMail(string senderMail, string senderName, ref string destMail[], ref string destName[], ref string subMail[], ref string msgMail[]) Library "SendInBluePB.dll" Alias For "SendMail;Ansi"

Here is how we declared the function in VisualStudio :
public static string SendMail(string senderMail, string senderName, string[] destMail, string[] destName, string[] subMail, string[] msgMail)
{
...
int i = destMail.Length; // Always return 1
...
}

We are new to C#, so could you tell us what we did wrong in the declaration of the functions please ?

Here is the list of all the packages we use in VisualStudio :

Accepted Answer
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 6 August 2020 14:18 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Christoiphe;

  FWIW: If you upgrade to PB 2019 R2, then you can call a .NET DLL directly from within a PB App. That is a new feature added to this release BTW. Food for thought.

FYI: https://docs.appeon.com/pb2019r2/whats_new/ch01s03.html

Regards ... Chris

Comment
  1. Christophe Feyte
  2. Thursday, 6 August 2020 15:27 PM UTC
Hello, it can be a good solution, but we will have to do a battery of non-regression tests of our application if we migrate to the new version of PB.

For the time being, we are looking for the cheapest solution.
  1. Helpful
There are no comments made yet.
Christophe Feyte Accepted Answer Pending Moderation
  1. Tuesday, 6 October 2020 08:03 AM UTC
  2. PowerBuilder
  3. # 1

Hello, well after upgrading to PB2019 R2, it works.

We used the ".NET DLL Importer", and that solved our problem.

Comment
There are no comments made yet.
Ricardo Jasso Accepted Answer Pending Moderation
  1. Thursday, 6 August 2020 17:11 PM UTC
  2. PowerBuilder
  3. # 2

Can you show the line where you make the call to the SendMail function in PowerScript along with the declaration of the local array for the destMail[] argument?

The local array should be sent without brackets, otherwise you'll be passing just one element of the array.

 

 

Comment
  1. Andrew Barnes
  2. Wednesday, 2 September 2020 20:34 PM UTC
I have never consumed a C# library using COM, always having used a C++ wrapper library that I coded 10-15 years back. That said, the Ansi declaration in the alias seems wrong. PB2019 is Unicode as should be C#.

What the Ansi keyword in your alias does is to tell PowerBuilder to convert Strings from 2 byte Unicode characters to 1 byte Ansi characters on the function call and to reverse the process for anything returns.

Typically this would be used if your were calling a standard DLL function that used ANSI strings such the Win32 API function FindWindowA which would be declared as

FUNCTION uLong FindWindow(String class, String Title) LIBRARY "USER32.DLL" ALIAS FOR "FindWindowA;Ansi"

On the other hand, calling the Unicode variant FindWindowW and still specifying Ansi would not work and probably blow up so it would be simply declared without it

FUNCTION uLong FindWindow(String class, String Title) LIBRARY "USER32.DLL" ALIAS FOR "FindWindowW"

Try removing the Ans, and see if that helps.
  1. Helpful
  1. Christophe Feyte
  2. Thursday, 10 September 2020 12:35 PM UTC
Thank you for your answers.

Unfortunately, I removed the Ansi but it still doesn't work.

  1. Helpful
  1. Ricardo Jasso
  2. Thursday, 10 September 2020 14:17 PM UTC
1) Does the senderMail and senderName succesfuly pass through the C# function?

2) If you can pass single string arguments but not string array arguments then I'd suggest you serialize the string array to a single JSON string (or other format) and deserialize it in the C# function. The purpose will be to use only single string arguments in the C# function.
  1. Helpful
There are no comments made yet.
Armeen Mazda @Appeon Accepted Answer Pending Moderation
  1. Thursday, 6 August 2020 13:46 PM UTC
  2. PowerBuilder
  3. # 3

Why not just directly call their REST APIs from PowerScrript using the RESTClient?  https://docs.appeon.com/pb2019r2/objects_and_controls/ch02s87.html

Comment
  1. Christophe Feyte
  2. Thursday, 6 August 2020 15:26 PM UTC
Hello, we've never used REST APIs before, so we have less knowledge than with the C# dlls.

But maybe we'll look into that as well.
  1. Helpful
  1. Christophe Feyte
  2. Thursday, 6 August 2020 15:26 PM UTC
Hello, we've never used REST APIs before, so we have less knowledge than with the C# dlls.

But maybe we'll look into that as well.
  1. Helpful
  1. Armeen Mazda @Appeon
  2. Thursday, 6 August 2020 15:41 PM UTC
Once you learn how to call REST APIs it opens up a whole new world of possibilities. Today it is SendInBlue's APIs, but tomorrow will be something else. I recommend you go through the resources at the bottom of this page, especially the REST Bootcamp video: https://www.appeon.com/products/powerbuilder/dotnet-datastore-rest-apis

  1. Helpful
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.