dll source
====================================
type
aa=record
a:String;
b:String;
end;
Function Arr(a,b:Integer):aa; export;
var ab : aa;
begin
ab.a := intTostr(a);
ab.b := intTostr(b);
Result := ab;
end;
exports
Arr;
=======================================
delphi source
=======================================
test.exe
type
aa=record
a:String;
b:String;
end;
procedure TForm1.Button1Click(Sender: TObject);
var iDllHandll : integer;
DllFunc : Function (a,b:Integer):aa;
ab : aa;
begin
iDllHandll := LoadLibrary('Project1.dll');
if iDllHandll >= 32 then begin
@DllFunc := GetProcAddress(iDllHandll, 'Arr');
if @DllFunc <> Nil then begin
ab := DllFunc(4,6);
showmessage(ab.b);
end;
FreeLibrary(iDllHandll);
end;
end;
delphi source 에서 버튼을 누르면 ab.b 값이 뜨긴 하는데 ok 버튼을 누르면
다음과 같은 에러가 뜹니다.
에러메시지
Access violation at address 00404228 in module 'test.exe'. Read of address 01160AE4.
dll source
====================================
type
paa=^aa; //add pointer type
aa=record
a:String;
b:String;
end;
Function Arr(a,b:Integer):paa; stdcall; //호출방식변경
begin
new(result); // 새 포인터변수정의 !!
result^.a := intTostr(a); //
result^.b := intTostr(b); //
end;
exports
Arr;
=======================================
delphi source
=======================================
test.exe
type
paa=^aa; //add pointer type
aa=record
a:String;
b:String;
end;
procedure TForm1.Button1Click(Sender: TObject);
var iDllHandll : integer;
DllFunc : Function (a,b:Integer):paa; stdcall; //수정
ab : paa; //수정
begin
iDllHandll := LoadLibrary('Project1.dll');
if iDllHandll >= 32 then begin
DllFunc := GetProcAddress(iDllHandll, 'Arr');
if @DllFunc <> Nil then begin
ab := DllFunc(4,6);
showmessage(ab^.b); //수정
end;
FreeLibrary(iDllHandll);
end;
end;