Call functions in external DLL (1. Early binding)

Source: Internet
Author: User
Unit unit1; interfaceuses windows, messages, extensions, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; Procedure button1click (Sender: tobject); Private {private Declarations} public {public declarations} end; var form1: tform1; // declaration of the mb function: function MB (hwnd: hwnd; lptext, lpcaption: pchar; utype: uint): integer; stdcall; implementation {$ R *. DFM} {call functions in external DLL, such as calling messageboxa} // function MB (hwnd: hwnd; lptext, lpcaption: pchar; utype: uint) in system user32.dll: integer; // stdcall; External USER32 name 'messageboxa '; {USER32 is the constant 'user32. dll ', which can be directly written as:} // function MB (hwnd: hwnd; lptext, lpcaption: pchar; utype: uint): integer; // stdcall; External 'user32. DLL 'name' messageboxa '; {name indicates the real name of the function} {external clause indicates that the function is loaded when the unit is loaded, that is, the function is bound early; if the late binding requires the loadlibrary} {stdcall command to indicate that the parameter is passed from right to left (Pascal is the opposite ), data Types that do not pass through the CPU register} {4 parameters can use the corresponding Delphi data type, for example:} // function MB (hwnd: longword; lptext, lpcaption: pchar; utype: longword): integer; // stdcall; External 'user32. DLL 'name' messageboxa '; {or:} // function MB (hwnd: Cardinal; lptext, lpcaption: pchar; utype: Cardinal): integer; // stdcall; external 'user32. DLL 'name' messageboxa '; {if a function is declared in this unit and needs to be called by another unit, declare:} // function MB (hwnd: Cardinal; lptext, lpcaption: pchar; utype: Cardinal): integer; // stdcall; {This example has already been done. If you want to test other cases, you need to comment out} {and then explain the function source in implementation:} function MB; External 'user32. DLL 'name' messageboxa '; // call test: Procedure tform1.button1click (Sender: tobject); var T, B: pchar; begin T: = 'title'; B: = 'content'; MB (0, B, T, 0); 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.