读书人

Delphi 7中访问DLL,报错‘Access Viol

发布时间: 2012-02-13 17:20:26 作者: rapoo

Delphi 7中访问DLL,报错‘Access Violation at address 00404B50 in moudle'ElisaStar.exe'.Read of address 03BE0B08’.
procedure TMainForm.mmiHelpClick(Sender: TObject);
Type
TCommuConnect_ErrorCodes=Function(x:byte):String;stdcall;
var
Commu_Code:byte;
Th:THandle;
Tf:TCommuConnect_ErrorCodes;
Tp:TFarproc;
begin
comBioMed :=CreateOLEObject( 'BioMed.Instruments ');
Commu_Code :=comBioMed.SetSetting(USB_Communicate);
try
Th:=LoadLibrary(PChar( 'ErrorHandling.dll '));
if Th> 0 then
@Tf:=GetProcAddress(Th,PChar( 'CommuConnect_ErrorCodes '));
if Assigned(Tf) then
begin
Label1.Caption:=Tf(Commu_Code);
end;
finally
FreeLibrary(Th);//单步执行到这是报上述错误
end;
end;
此程序是完成返回一个字符串功能,报‘Access Vilolation at address.....’错误,但字符还能正常返回来显示。


[解决办法]

在DLL中使用String类型:
1、在你的DLL项目源文件中第一个引用ShareMem单元;
2、你必须在你的应用程序项目源文件中第一个引用SHAREMEM单元;

读书人网 >.NET

热点推荐