2011-05-27 102 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