ورود

View Full Version : The memory Could not be read



Sir.V65j
سه شنبه 24 شهریور 1388, 09:15 صبح
سلام دوستان عزيز
يه برنامه با دلفي نوشتم + يه dll
فايل dll رو توي برنامم لود (با LoadLibrary)مي كنم و از يه تابعش استفاده مي كنم (اين تابع Export شده و يه داده اي هم برميگردونه ) ولي وقتي هندل dll رو FreeLibrary مي كنم با ارور

http://barnamenevis.org/forum/attachment.php?attachmentid=36962&stc=1&d=1252991352

رو به رو مي شم اينم تيكه كد فراخواني و ...





type
TDLLFunc = procedure(var ar: array of integer);
// TDLLFunc1 = procedure;

{assign a nil - not loaded function}
var
DLLFunc: TDLLFunc ;
DLLHandle: THandle;
{handle of loaded dll}
Function myf(ss:string):string;
var
vv:array [1..16] of integer;
DLLName:string;
begin
{ load a library }
DLLName:='c:\1.dll';
DLLHandle := LoadLibrary(pchar(DLLName));

if (DLLHandle < HINSTANCE_ERROR) then
raise Exception.Create(DLLName + ' library can not be loaded or not found. ' + SysErrorMessage(GetLastError));

try
{ load an address of required procedure}
@DLLFunc := GetProcAddress(DLLHandle, 'Wi');
{if procedure is found in the dll}
if Assigned(DLLFunc) then

DLLFunc(vv);
Result:= ss + 'OK';
finally
{unload a library}
FreeLibrary(DLLHandle);
end;
end;