我使用RobertGiesecke的託管輸出NuGet包,以便把它在delphi5 Win32應用程序導出一個.NET的DLL函數返回自定義類型的實例。傳遞和返回標準類型時 一切工作完美(字符串,整數......)。 但我嘗試按照編組樣品(https://sites.google.com/site/robertgiesecke/Home/uploads#TOC-Marshalling-sample)返回在C#中定義的自定義類型的實例,但我不管理,以正確訪問在delphi實例。不能與非託管的出口(羅伯特·捷)
在Delphi中,我的代碼是:
type
TCreateSampleInstance = procedure(var sample: PSample); stdcall;
TSample = record
Name: WideString;
end;
PSample = ^TSample;
var
sample: PSample;
dllHandle: Cardinal;
proc4: TCreateSampleInstance;
begin
dllHandle := LoadLibrary('myDotNetAssembly.dll');
if dllHandle <> 0 then
try
@proc4 := GetProcAddress(dllHandle, PChar('CreateSampleInstance'));
if Assigned(proc4) then
begin
proc4(sample);
// how to access sample properties ?
Caption := sample^.Name; // Name = '' here instead of 'Test'...
end;
finally
FreeLibrary(dllHandle);
end;
end;
預先感謝您的幫助!
FWIW,在互操作問題中,您應該始終顯示互操作邊界的兩側 –