我想用新项目扩展默认的扬声器通知(托盘图标)右键单击上下文菜单。另外,我想用C ++处理鼠标点击。
插图
到目前为止我所知道的
我学习了如何使用 CreateRemoteThread()进行dll-inject,因为我觉得这是要走的路。我的问题是:在注入的dll中做什么?例如,如何访问NotifyIcon对象?
也许可以使用简单的Windows API调用,但我不熟悉它。
答案 0 :(得分:2)
感谢卢克提示。我使用EasyHook开始工作了。我之所以选择它,是因为它还支持64位dll-inject。
要注入的DLL:
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using EasyHook;
namespace InjectDLL
{
public class Main : EasyHook.IEntryPoint
{
LocalHook CreateTrackPopupMenuExHook;
public Main(RemoteHooking.IContext InContext){}
public void Run(RemoteHooking.IContext InContext)
{
try
{
CreateTrackPopupMenuExHook = LocalHook.Create(
LocalHook.GetProcAddress("user32.dll", "TrackPopupMenuEx"),
new DTrackPopupMenuEx(TrackPopupMenuEx_Hooked),
this);
CreateTrackPopupMenuExHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
}
catch
{
return;
}
while (true)
{
Thread.Sleep(500);
}
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool AppendMenu(IntPtr hMenu, long uFlags, int uIDNewItem, string lpNewItem);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, CallingConvention = CallingConvention.StdCall)]
static extern IntPtr TrackPopupMenuEx(
IntPtr hMenu,
uint fuFlags,
int x,
int y,
IntPtr hwnd,
IntPtr lptpm);
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Auto, SetLastError = true)]
delegate IntPtr DTrackPopupMenuEx(
IntPtr hMenu,
uint fuFlags,
int x,
int y,
IntPtr hwnd,
IntPtr lptpm);
const long MF_STRING = 0x00000000L;
const long MF_SEPARATOR = 0x00000800L;
static IntPtr TrackPopupMenuEx_Hooked(
IntPtr hMenu,
uint fuFlags,
int x,
int y,
IntPtr hwnd,
IntPtr lptpm)
{
IntPtr returnValue = IntPtr.Zero;
try
{
//Separator
AppendMenu(hMenu, MF_SEPARATOR, 0, null);
//New menu item
AppendMenu(hMenu, MF_STRING, 40010, "TestMenuItem");
//call the default procedure
returnValue = TrackPopupMenuEx(hMenu, fuFlags, x, y, hwnd, lptpm);
//our menu item is selected
if (returnValue == (IntPtr)40010)
{
/* CODE HERE */
returnValue = IntPtr.Zero;
}
return returnValue;
}
catch
{
return;
}
return returnValue;
}
}
}