Skip to Content
0

PowerBuilder - Error calling an external function

Apr 06, 2017 at 08:37 PM

763

avatar image
Former Member

Hi,

I am trying to call a function located in a DLL that was developed for us. When I try to run the script it is showing me the following error: "Error opening DLL library Encryption.dll for external function at line ....... ".

How I am defining the External functions on PowerBuilder?

Function string EncryptStringAES &
(string plainText, &
string sharedSecret &
) Library "Encryption.dll" Alias For "EncryptStringAES"


Function string DecryptStringAES &
(string cipherText, &
string sharedSecret &
) Library "Encryption.dll" Alias For "DecryptStringAES"

How they are in the DLL ?

The class name is Crypto, and it is in the Encryption namespace.

public static string EncryptStringAES(string plainText, string sharedSecret)

public static string DecryptStringAES(string cipherText, string sharedSecret)

I am using PB 10.2.1 , for now!

Thanks.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

avatar image
Former Member Apr 06, 2017 at 09:51 PM
0

Hi Luis;

If your DLL developer did not create the DLL as per Unicode specifications - as is PB 10.x - you might need to add the following to the external declaration, as follows ....

Function string EncryptStringAES &
(string plainText, &
string sharedSecret &
) Library "Encryption.dll" Alias For "EncryptStringAES;ansi"


Function string DecryptStringAES &
(string cipherText, &
string sharedSecret &
) Library "Encryption.dll" Alias For "DecryptStringAES;ansi"

HTH

Regards ... Chris

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Chris, thanks for your answer.

The developer is not sure about the Unicode specifications, but as you said I added the ;ansi keyword on both, and I still have the same problem.

Luis.

0
avatar image
Former Member Apr 07, 2017 at 03:35 AM
0

Another way to show my issue:

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

The dll was built on the .NET 2.0 and 4.0 Framework trying to identify the issue.

---

using System;

using System.Collections.Generic;

using System.Text;

namespace Test

{

publicclassClass1

{

publicstring HelloWorld()

{

return"Hello";

}

publicstring HelloWorld2(string test)

{

return test;

}

publicvoid HelloWorld3(string test1, outstring test2 )

{

test2 = test1;

}

}

}

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

Local external Function definition:

Function string HelloWorld2 &
(string test &
) Library "Test.dll" Alias For "HelloWorld2;ansi"

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

Calling the external function:

String ls_value, ls_returned

ls_value = Trim(sle_source.text)

ls_returned = HelloWorld2(ls_value)

IF Not IsNull(ls_returned) THEN
sle_encrypted.text = ls_returned
END IF

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

Share
10 |10000 characters needed characters left characters exceeded
René Ullrich Apr 07, 2017 at 06:25 AM
0

I think you have a .NET assembly and not a normal dynamic link library. The file extension for an assembly is .DLL but it is not a real Windows DLL! So you can't use it this way.

https://forums.asp.net/t/1536669.aspx?Difference+between+normal+DLL+net+DLL

You may use the assembly as a COM object.

http://pbdj.sys-con.com/node/1668463

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Apr 07, 2017 at 04:47 PM
0

A .Net DLL can only be used by a .Net application unless it is exposed as COM. To use a COM DLL from PowerBuilder you need to use the ConnectToNewObject function to establish an OLEObject variable. See the excellent article on pbdj linked above for more detail.

Alternately you could abandon the .Net DLL entirely and call the encryption functions directly. I have two different sample apps:

http://www.topwizprogramming.com/freecode_cryptoapi.html

http://www.topwizprogramming.com/freecode_bcrypt.html

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Apr 14, 2017 at 02:29 PM
0

Thanks everyone for your comments, they were very helpful for me.

For now we will use a third party DLL for the encryption process. Your information will help me when we migrate to PB 12.6 in a couple of months.

Thanks!!!

Share
10 |10000 characters needed characters left characters exceeded