[英]Using C# WinForm to send application registration information to a my gmail
[英]External application crashes after using easyhook and one function to send information from the dll to my c# code
我使用的是easyhook,退出應用程序后,被鈎住的那個崩潰了。 我知道發生的地方,但不知道如何解決。 我鈎上DrawText。 我什么都不做:
int DrawText_Hooked(IntPtr hdc, [In, Out, MarshalAs(UnmanagedType.LPTStr)] string lpString, int cchText, [In, Out, MarshalAs(UnmanagedType.Struct)] ref RECT lprc, uint dwDTFormat, [In, Out, MarshalAs(UnmanagedType.Struct)] ref DRAWTEXTPARAMS dparams)
{
//Interface.Read(hdc, lpString, cchText, dwDTFormat);
return DrawTextExW(hdc, lpString, cchText, ref lprc, dwDTFormat, ref dparams);
}
但是,如果我取消注釋Interface.Read(...)
,則當我退出c#程序時,它將使我的鈎子應用程序崩潰(否則,它可以正常運行)。
該函數在我的C#代碼中,看起來是這樣的:
public class interfaceA : MarshalByRefObject
{
public void ReportException(Exception InInfo)
{
}
public void Ping()
{
}
public void Read(IntPtr hdc, string lpString, int cchText, uint dwDTFormat)
{
Console.WriteLine(lpString);
}
}
我該怎么做才能防止此外部應用程序崩潰? 或者如何在沒有此問題的情況下將信息從dll發送到C#代碼?
謝謝
我不知道為什么會這樣,經過進一步調查后,一旦知道那是什么錯誤,我就得到了答案。 在完全解決之前,我問了另一個問題,這里是鏈接:
舊問題,但萬一有人偶然發現此問題以尋找答案。
崩潰的實際原因是,當您關閉C#程序時IPC服務器已關閉,因此嘗試訪問Interface
對象將失敗。
要解決此問題,請在Interface.Read調用周圍使用try..catch
,或者在退出托管IPC服務器的C#程序之前通過發出信號來禁用掛鈎(卸載)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.