Calling functions in a DLL written in. NET in Delphi

Source: Internet
Author: User

Recently because the company mass mail program needs to register for a period of time has not activated the user to activate the mail, the message has registered password needs to be restored to the user but because the password encryption is used in C # TripleDES complete, on hand and no ready-made Delphi implementation. Time is urgent, now the translation is too late, so after the search data repeatedly implemented successfully implemented in Delphi in C # encapsulated DLL methods (Function) and process (Procedure) is to write down the implementation steps for the XDJM to share:

1, establish: DotNetFunc.cs encapsulation to use the function, Procedure.

2, generate the key file, for the assembly strong name signature

Sn-k key.snk

3, the use of strong name signature, compiled into class library

Csc/t:library DotNetFunc.cs

4. Build Type library

TlbExp dotnetfunc.dll/out:dotnetfunc.tlb

5. Register DLL

RegAsm DotNetFunc.dll

6. Move into GAC Global assembly cache

Gacutil-i DotNetFunc.dll

7, Delphi in the call test

Uses variants, Comobj, Olectnrs, Activex;
Procedure Tform1.button1click (Sender:tobject);
Var
Sharpobject:variant;
testvalue:string;
Begin
Try
Try
Sharpobject: = Createoleobject (' Csharpserver.sharpobject ');
TestValue: = Sharpobject.decrypttripledes (Edit1.text);
Edit2.text: =testvalue;
Except
On E:exception do
Begin
ShowMessage (E.message);
End
End
Finally
Sharpobject: = unassigned;
End
End
Procedure Tform1.button2click (Sender:tobject);
Var
Sharpobject:variant;
testvalue:string;
Begin
Try
Try
Sharpobject: = Createoleobject (' Csharpserver.sharpobject ');
TestValue: = Sharpobject.encrypttripledes (Edit2.text);
Edit1.text: =testvalue;
Except
On E:exception do
Begin
ShowMessage (E.message);
End
End
Finally
Sharpobject: = unassigned;
End
End
Initialization
CoInitialize (nil);
Finalization
CoUninitialize;
End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.