2011-05-27 143 views
4

我需要从这个德尔福棱镜类库在Delphi XE方法“验证”访问:访问德尔福棱镜类库德尔福XE

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 
[...] 

这是很容易的串扰,但串扰非常昂贵,此代码适用于一个宠物项目。任何简单的方法来做到这一点?

TIA

回答

5
function Auth(userName: PAnsiChar; userPassword: PAnsiChar): PAnsiChar; stdcall; external 'ClassLibrary1.dll' 

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

+0

这对我来说似乎不太令人信服。 – 2011-05-27 20:06:22

+1

你是什么意思?这是Delphi Prism的一个功能:http://prismwiki.codegear.com/en/Unmanaged_Exports。 – 2011-05-27 20:12:22

+1

Lars字符串作为ANSI字符串编组,所以声明必须是'function Auth(userName:PAnsiChar; userPassword:PAnsiChar):PAnsiChar; STDCALL;外部'ClassLibrary1.dll';' – RRUZ 2011-05-27 20:26:25