1. Igor Perisic
  2. PowerScript Migrator
  3. Wednesday, 26 October 2022 17:38 PM UTC

Hi!

I am converting a few PowerBuilder apps to C# but I am not sure how to convert dlls from PowerBuilder to C#.

One of my dlls in PB is defined as FUNCTION longptr Decrypt(ref longptr decryptMem) LIBRARY "DecryptDLL.dll" alias for "Decrypt;Ansi"

I call this function in PB like so, LocalErrorCode = Decrypt(decryptMem), where decryptMem is a longptr and LocalErrorCode is an int.

 

And then in C# I have it defined as

[DllImport("DecryptDLL.dll")]
private static extern long Decrypt(ref long decryptMem);
 
When I call this function inside my C# app I get returned the wrong values.
I call it like so LocalErrorCode = (int)Decrypt(ref decryptMem); where decryptMem is a long and LocalErrorCode is an int. 
 
Inside PB: LocalErrorCode is 0 and decryptMem is 3062099201824. Which is what it should be
Inside C#: LocalErrorCode is -1105657857 and decryptMem is 2571579608608.
 
Not exactly sure where I am messing up, maybe I have variables defined as the wrong type. Does C# need to have a line like PB does for "alias for "Decrypt;Ansi""?
 
Roland Smith Accepted Answer Pending Moderation
  1. Wednesday, 26 October 2022 20:02 PM UTC
  2. PowerScript Migrator
  3. # 1

Since you are going through the bother of rewriting PB to C#, you should do the encryt/decrypt using C# native methods.

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 26 October 2022 19:48 PM UTC
  2. PowerScript Migrator
  3. # 2

Hi, Igor -

Why are you trying to utilize a decryption DLL when (I assume) there are native C# objects available to do this? I'm not very C# knowledgeable, but this appears an unusual approach to decrypting data. I'm also not sure why the external function declaration in PB specifies ANSI translation, since both the argument value and return value for the DLL entry point/function are numeric. Is this DLL from a third-party source? If so, perhaps the vendor/author has a C# solution.

Best regards, John

Comment
  1. Armeen Mazda @Appeon
  2. Wednesday, 26 October 2022 20:02 PM UTC
Adding to what John said, it is not best practice to have unmanaged code (e.g. C++ DLL) in a .NET project. If the functionality of this DLL is natively supported in .NET, it is strongly recommend to change your implementation as such.
  1. Helpful
There are no comments made yet.
Francisco Martinez @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 26 October 2022 18:17 PM UTC
  2. PowerScript Migrator
  3. # 3

Hi Igor,

I'm not all too familiar with this topic, but something caught my eye: you're declaring the external function in C# as taking and returning longs, but you catch/pass ints.

I wonder if this discrepancy could have something to do with the issue.

Regards,
Francisco

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.