1.delphi dllçªä½è¿å主ç¨åºçªä½
2.Delphi中DLL调用后如何完全释放
delphi dllçªä½è¿å主ç¨åºçªä½
DLLä¸çªä½çOwneræ¯ä»ä¹ï¼è¿æçªä½çæé å½æ°æ¯æä¹åçï¼âå¦ææ³ä»DLLçªä½ä¸è¿å主ç¨åºçªä½âè¿å¥ä¸æ¯ååç解ï¼è½è§£éä¸ä¸å? 追é®ï¼ DLLä¸çªä½çOwner 没æææ³çæ¯ DLLçªä½æ¾ç¤ºåºæ¥ä»¥å å¦æå¯ç é误çé®é¢ è¦è¿åç»éçªä½ ç»éçªä½æ¯è°ç¨è¯¥DLLçdllï¼procedure showform(LL_id:string);beginApplication.CreateForm(TFuser_list, Fuser_list);fuser_list.Caption:=ll_id+'å¨çº¿';my_id:=ll_id;Fuser_list.Show ;//è¿æ¥æ°æ®åº è·å好åå表end; åçï¼ DLLæé çªä½çæ¶åæ好æ主çªä½çæéä½ä¸ºOwner:TComponentä¼ éè¿æ¥ï¼ç¶åä½ å¯ä»¥éè¿use主çªä½æä½ä¸»çªä½(Owner)äºvar Fuser_list:TFuser_list;begin Fuser_list := TFuser_list.Create(Owner);end; è¡¥å ï¼ ä½ ä¹å¯ä»¥æDLLæé åºæ¥ççªä½æéè¿åç»ä¸»çªä½çãä¸å¥½ææDephiä¸æä¹ä¼ç¨ï¼åçæ¯è¿æ ·çï¼ä»£ç ä¸å¸®ä¸ä¸å¤ªå¤ã 追é®ï¼ ä»ä¹æ¯use主çªä½ï¼ å¦æ主çªä½å·²ç»éæ¾äºï¼ è¿è½åæ¾ç¤ºåºæ¥ï¼ åçï¼ æ主çªä½ç.pasæ·è´å°dllç®å½ä¸ï¼ç¶åuse主çªä½ç±»ï¼å¨DLLççªä½å°±å¯ä»¥æä½ä¸»çªä½éçå ç´ äºå 主çªä½éæ¾Applicationå°±ç»æäºå§ï¼DLLççªä½ä¹ä¼å ³æç è¡¥å ï¼ çä¸æå¾æ¾æ¾ï¼ä»¥ååè¿ä¸ä¸ªC++Builderç è¡¥å ï¼ int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved){ return 1;}//---------------------------------------------------------------------------extern "C" __declspec(dllimport) TForm * __stdcall ShowLogonForm(TComponent* Owner);//---------------------------------------------------------------------------
Delphi中DLL调用后如何完全释放
Delphi有静态加载Dll和动态加载Dll,静态加载的Dll不用我们释放;动态加载需要我们自己释放;
这里只附上动态加载DLL的释放(此处Dll和Exe程序在同一路径下):
procedure TForm1.Button2Click(Sender: TObject);
var MyHandle:THandle ;
FPointer:Pointer;
MyDll_Func: function (s:string):Integer;stdcall;
begin
try
try
MyHandle:=LoadLibrary('project1.Dll') ;
if MyHandle<>0 then
begin
FPointer:=GetProcAddress(MyHandle ,PChar(Edit1.text));
if FPointer<>nil then
begin
MyDll_Func:=FPointer;
MyDll_Func(Edit1.text) ;
end
else
ShowMessage('此'+Edit1.text+'方法,在project1.Dll中不存在');
秋梦源码end
秋梦源码except
秋梦源码showmessage('加载project1.Dll异常');
秋梦源码end;
秋梦源码finally
秋梦源码FreeLibrary(MyHandle) ;
秋梦源码end;
秋梦源码end;
秋梦源码2024-12-22 11:41
2024-12-22 11:31
2024-12-22 10:44
2024-12-22 10:34
2024-12-22 10:31
2024-12-22 10:15