Call functions in external DLL (2. Bind later)

Source: Internet
Author: User
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type // late binding, that is, to call an external function dynamically, use the following three commands: // loadlibrary: Get DLL // getprocaddress: Get function // freelibrary: Release // define a process type, the parameter must be consistent with the required function. TMB = function (hwnd: hwnd; lptext, lpcaption: pchar; utype: uint): integer; stdcall; tform1 = Class (tform) button1: tbutton; procedure button1click (Sender: tobject); Procedure formcreate (Sender: tobject); Procedure formdestroy (Sender: tobject); Private MB: TMB; {declaration function MB} inst: longword; {declare a variable to record the DLL handle to be used} public {public declarations} end; var form1: tform1; implementation {$ R *. DFM} procedure tform1.formcreate (Sender: tobject); begin inst: = loadlibrary ('user32. dll '); If inst 0 then MB: = getprocaddress (Inst, 'messageboxw'); // MB: = getprocaddress (Inst, 'messageboxa '); {use this sentence for versions earlier than Delphi 2009} end; // call the test: Procedure tform1.button1click (Sender: tobject); var T, B: pchar; begin T: = 'title '; b: = 'content'; MB (0, B, T, 0); end; Procedure tform1.formdestroy (Sender: tobject); begin freelibrary (insT); {remember to release} end; 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.