Tôi có tập lệnh Inno Setup đang chạy, trong đó tôi sử dụng innocallback.dll bởi Phần mềm Sherlock.Gọi C# DLL từ Thiết lập Inno với gọi lại
DLL này kết thúc tốt đẹp một thủ tục của tôi để nó có thể được chuyển cho C# DLL.
Tôi không muốn sử dụng DLL này, tôi muốn gọi phương thức C# đã xuất của tôi trực tiếp và chuyển đến thủ tục gọi lại.
Câu hỏi của tôi là:
Làm thế nào tôi có thể vượt qua thủ tục cài đặt Inno của tôi (@mycallback
) đến C# DLL của tôi để tôi có thể sử dụng nó như tôi delegate
/UnmanagedFunctionPointer
?
Như tôi đã nói mã này hoạt động, nhưng tôi muốn sử dụng càng ít DLL bên ngoài càng tốt.
Đây là mã của tôi:
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;
Và đây là C của tôi # mã
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);
}
}
Tôi chỉ thấy bạn đã nhận INNO-setup Badge vàng . Xin chúc mừng :) – Bongo