Sherlock Software tarafından innocallback.dll kullandığım çalışan bir Inno Setup komut dosyası var.Geri Çağırma ile Inno Kurulum gelen C# DLL çağrısı
Bu DLL, bir C# DLL dosyasına geçirilebilmesi için benimki bir prosedürü tamamlar.
Bu DLL'yi kullanmak istemiyorum, verilen C# yöntemimi doğrudan aramak ve geri arama yordamına iletmek istiyorum.
Sorum şu:
benim delegate
/UnmanagedFunctionPointer
olarak kullanabilirsiniz böylece benim C# DLL benim Inno Setup prosedürünü (@mycallback
) geçebilir nasıl?
Bu kod çalıştığını söylediğim gibi, ancak olabildiğince az dış DLL kullanmak istiyorum. İşte
benim kodudur:Inno Setup Script
type
TTimerProc=procedure();
TProgressCallback=procedure(progress:Integer);
function WrapProgressProc(callback:TProgressCallback; paramcount:integer):longword;
external '[email protected]:innocallback.dll stdcall';
function Test(callback:longword): String;
external '[email protected]:ExposeTestLibrary.dll stdcall';
var
endProgram : Boolean;
procedure mycallback(progress:Integer);
begin
MsgBox(IntToStr(progress), mbInformation, MB_OK);
if progress > 15 then
begin
endProgram := True;
end
end;
function InitializeSetup:boolean;
var
progCallBack : longword;
callback : longword;
msg : longword;
msg2 : widestring;
begin
endProgram := False;
progCallBack:= WrapProgressProc(@mycallback,1); //Our proc has 1 arguments
Test(progCallBack);
result:=true;
end;
Ve bu sarma kullanımını bırakmak için bir yolu yoktur benim C# kodu
public class TestClass
{
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void ReportProgress(uint progress);
public static ReportProgress m_reportProgess;
static uint m_iProgress;
[DllExport("Test", CallingConvention = CallingConvention.StdCall)]
static int Test(ReportProgress rProg)
{
m_iProgress = 0;
m_reportProgess = rProg;
System.Timers.Timer pTimer = new System.Timers.Timer();
pTimer.Elapsed += aTimer_Elapsed;
pTimer.Interval = 1000;
pTimer.Enabled = true;
GC.KeepAlive(pTimer);
return 0;
}
static void aTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
m_iProgress++;
m_reportProgess(m_iProgress);
}
}
Sadece Inno-kurulum altın Rozet var gördü . Tebrik ederiz :) – Bongo