Пример #1
0
        static void Main()
        {
            using (System.Threading.Mutex mutex = new System.Threading.Mutex(false, Application.ProductName))
            {
                if (mutex.WaitOne(0, false))
                {
                    int hModule = LoadLibrary(@"Injection.dll");

                    if (hModule == 0)
                    {
                        MessageBox.Show("error:LoadLibrary failed.");
                        return;
                    }

                    IntPtr intPtrInstall = GetProcAddress(hModule, @"InstallHook");
                    IntPtr intPtrRemove  = GetProcAddress(hModule, @"RemoveHook");

                    if (intPtrInstall == IntPtr.Zero)
                    {
                        MessageBox.Show("error:InstallHook function is not included in Core.dll.");
                        FreeLibrary(hModule);
                        return;
                    }

                    if (intPtrRemove == IntPtr.Zero)
                    {
                        MessageBox.Show("error:intPtrRemove function is not included in Core.dll.");
                        FreeLibrary(hModule);
                        return;
                    }

                    HOOKFUNC InstallHook =
                        (HOOKFUNC)Marshal.GetDelegateForFunctionPointer
                            (intPtrInstall, typeof(HOOKFUNC));
                    HOOKFUNC RemoveHook =
                        (HOOKFUNC)Marshal.GetDelegateForFunctionPointer
                            (intPtrRemove, typeof(HOOKFUNC));

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);

                    InstallHook();

                    Application.Run(new MainForm());

                    RemoveHook();
                    FreeLibrary(hModule);
                }
            }
        }
Пример #2
0
 static extern IntPtr SetWindowsHookEx(int idHook, HOOKFUNC lpfn, IntPtr hMod, uint dwThreadId);