首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

Delphi调用VC的DLL后出错解决方案

2012-02-14 
Delphi调用VC的DLL后出错我调用了一个VC的dllTypeTafunction(a:string b: array of Integer):Integer s

Delphi调用VC的DLL后出错
我调用了一个VC的dll
Type
  Ta=function(a:string; b: array of Integer):Integer; stdcall;
  THandle=Integer;

然后我在一个buttonclick里调用
var
  a: array of integer;
  Handle: THandle;
  x: ta;
  y: string;
  i: integer;
begin
  y := 'safd';
  SetLength(a,5);
  Handle:=LoadLibrary('a.dll'); //这个dll是传入一字符串,及一个数组,最后得到的结果放传入的那数组里
  if Handle<>0 then
  begin
  x:=GetProcAddress(Handle,pchar('Calc'));

  x(y,a);
   
  for i:=0 to 4 do
  begin
  QuickReport.label1.Caption := a[i];
  ...
  end;
  end;
  setlength(a,0);
  a := nil;
end;

报表预览后,我一点close,就会出错:
Project faulted with message: 'access violation at 0x004cf806: write of adress 0x00000295'. Process Stopped

这应该就是那数组的问题吧,
请帮帮我,我该如何改

非常感谢!


[解决办法]
array of Integer是Delphi特有的类型,与VC不兼容

换成静态数组试试
[解决办法]
你把stdcall换成cdecl试试。
[解决办法]
VC写的DLL中一般是不会支持Delphi的String类型的, 建议楼主将VC的函数原型帖出来让大家看看。
[解决办法]
没有C++函数原型,谁也帮不了你。
[解决办法]
应该转换成PChar型,然后再转回来

热点排行