Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call dynamic Link Library in Delphi

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Delphi how to call dynamic link library, I believe that many people do not have experience in this helpless, this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Two Methods of Calling Dynamic Libraries

static call

The premise of this usage is that it is clear before compilation which functions in DLL are to be called, and only the necessary link information is retained in the object file during compilation, without the code of DLL function; when the program is executed, the DLL function code is loaded by using the link information and linked into the execution space of the calling program in memory, and its main purpose is to facilitate code sharing.

dynamic invocation

This means that you don't know which DLL functions will be called before compilation, and you decide which function should be called according to your needs during operation, and use LoadLibrary and GetProcAddress to dynamically obtain the entry address of DLL functions.

code demonstrates

We first create a dynamic link library named PosPayIntf, which is used in recent chapters to introduce Delphi technology, because it is precisely because the project needs to be a dynamic library for docking third-party Weixin Pay treasure. The entry function is PosPayOperate

function PosPayOperate(OpType: Integer; const InPara: PChar; OutPara, OutMsg: PChar): Integer; export; stdcall;

Then we create a new Application, adding two Memos, a combox and a Button button.

static call

Add under uses

const

SMCzkYw_DLL = 'PosPayIntf.dll'; //Call dynamic library name

function PosPayOperate(OpType: Integer; const InPara: PChar; OutPara, OutMsg: PChar): Integer; export; stdcall;

Then add under implementation

function PosPayOperate(OpType: Integer; const InPara: PChar; OutPara, OutMsg: PChar): Integer; external POSPAY_DLL;

So we can use it directly when we call it

Using static calls dynamic library code is relatively small, but our dynamic library must be placed and the EXE program, if the DLL file does not exist, the program can not run, prompt you less DLL file.

dynamic invocation

Today we mainly talk about dynamic calls, because if the DLL does not exist, or if there is a problem with the entry function, we can capture it by try except, and it will not affect the use of the main program.

We directly define a THandle and a TPublicFun in the button event that calls the dynamic library method. The TPublicFun is directed to our entry function.

Then load the dynamic library through LoadLibrary

Call in the same way as a static call

Finally, try finally to release the dynamic library

After reading the above, do you know how to call DLL in Delphi? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report