【问题标题】:Access Delphi Prism Class Library from Delphi XE从 Delphi XE 访问 Delphi Prism 类库
【发布时间】:2011-05-27 19:31:03
【问题描述】:

我需要在 Delphi XE 中访问此 Delphi Prism 类库中的“Auth”方法:

    namespace ClassLibrary1;

    interface

    uses
      System,
      System.IO,
      System.Security.Cryptography,
      System.Runtime.InteropServices,
      System.Text;

    type
      ConsoleApp = public class
      private
        class method hashMe(input: string): string;
        class method Encrypt(clearText: string; Password: string; Salt: array of byte; iteration: Integer): string;
        class method Encrypt(clearData: array of byte; Key: array of byte; IV: array of byte): array of byte;
        class method Encrypt(clearData: array of byte; Password: string; Salt: array of byte; iteration: integer): array of byte;
        class method Decrypt(cipherText: string; Password: string; Salt: array of byte; iterations: Integer): string;
        class method Decrypt(cipherData: array of byte; Password: string; Salt: array of byte; iterations: integer): array of byte;
        class method Decrypt(cipherData: array of byte; Key: array of byte; IV: array of byte): array of byte;
      protected
      public
        [UnmanagedExport('Auth')]
        class method Auth(userName: String; userPassword: String): String;
      end;

    implementation
[...]

使用 CrossTalk 这很容易,但是 CrossTalk 非常昂贵,并且此代码用于宠物项目。有什么简单的方法可以做到这一点?

TIA

【问题讨论】:

    标签: delphi delphi-prism


    【解决方案1】:
    function Auth(userName: PAnsiChar; userPassword: PAnsiChar): PAnsiChar; stdcall; external 'ClassLibrary1.dll' 
    

    但在非托管/win32 代码中返回 PAnsiChar 并不是一个好主意。谁来释放字符串?

    【讨论】:

    • 这对我来说似乎不是很有说服力。
    • 什么意思?这是 Delphi Prism 的一个功能:prismwiki.codegear.com/en/Unmanaged_Exports.
    • Lars 字符串被编组为 ANSI 字符串,因此声明必须为 function Auth(userName: PAnsiChar; userPassword: PAnsiChar):PAnsiChar; stdcall; external 'ClassLibrary1.dll';
    • 谢谢你,RRUZ,会改变我的答案
    • 我也找到了这个答案,看起来这很完美。谢谢大家。 stackoverflow.com/questions/2273141/…
    猜你喜欢
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2011-11-17
    • 2019-03-16
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多