동적으로로드 된 DLL에서 호스트 프로그램의 TDictionary 변수에 액세스하려고 할 때 매우 심각한 문제가 발생합니다. 여기에 완전한 코드가 있습니다. 누구든지 도움을 줄 수 있습니까? 감사!큰 문제가 있습니다 : TDictionary 및 Delphi 2010에서!
=========== 메인 프로그램 프로젝트 소스 코드 ===================
program main;
uses
ShareMem,
Forms,
uMain in 'uMain.pas' {Form1},
uCommon in 'uCommon.pas';
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
==== ========== 부 uMain ================
unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, uCommon;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
Tfoo = function(ADic: TMyDic): string; stdcall;
procedure TForm1.Button1Click(Sender: TObject);
var
Dic: TMyDic;
HLib: THandle;
foo: Tfoo;
begin
Dic := TMyDic.Create;
try
Dic.Add(1, 'World!');
Dic.Add(2, 'Hello, ');
HLib := LoadLibrary('Mydll.dll');
try
@foo := GetProcAddress(HLib, 'foo');
ShowMessage(foo(Dic));
finally
FreeLibrary(HLib);
end;
finally
Dic.Free;
end;
end;
end.
=============== == dll 프로젝트 소스 코드 ===================
library MyDll;
uses
ShareMem,
SysUtils,
Classes,
uCommon in 'uCommon.pas';
function foo(ADic: TMyDic):string; stdcall;
var
I: Integer;
S: string;
begin
for I in ADic.Keys do
begin
S := S + ADic[I];
end;
Result := s;
end;
exports
foo;
end.
============== unit uCommon ==============
unit uCommon;
interface
uses
SysUtils, Generics.Collections;
type
TMyDic = TDictionary<Integer, string>;
implementation
end.
StackOverflow에 오신 것을 환영합니다. Neo.당신은 코드에 대해 아주 잘 설명해 주었고이 상황에서 잘못 될 가능성이있는 것에 대한 최선의 추측을 바탕으로 질문에 대답하려고 시도했지만 실제로 문제를 설명하면 더 나은 결과를 얻을 수 있습니다 *뿐만 아니라. "이 코드를 사용하면 프로그램에서의 세 번째 줄에 예외가 발생합니다." –
AFAIK, Delphi 2010! 아직 공개되지 않았습니다. –