取得本dll路径的方法及按键Hook的方法
本帖最后由 badboy518 于 2012-8-4 10:48 编辑public static class Xsys
{
/// <summary>
/// 取得本dll的路径
/// </summary>
/// <returns></returns>
public static string GetAssemblyPath()
{
string _CodeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
_CodeBase = _CodeBase.Substring(8, _CodeBase.Length - 8); // 8是 file:// 的长度
string[] arrSection = _CodeBase.Split(new char[] { '/' });
string _FolderPath = "";
for (int i = 0; i < arrSection.Length - 1; i++)
{
_FolderPath += arrSection + "/";
}
return _FolderPath;
}
}
/// <summary>
/// 消息Hook,目前仅Hook了WM_KEYDOWN,事件发生时会发送回按键码
/// </summary>
public class MessageHook
{
const int WM_KEYDOWN = 0x100;
public delegate void KeyDown(int keycode);//事件所需要的委托(注意,声明委托,必须加上括号)
public event KeyDown OnKeyDown;//事件声明
public void SetKeyHook()
{
Application.PreTranslateMessage += Application_PreTranslateMessage;
}
public void UnKeyHook()
{
Application.PreTranslateMessage -= Application_PreTranslateMessage;
}
void Application_PreTranslateMessage(object sender, PreTranslateMessageEventArgs e)
{
if (e.Message.message == WM_KEYDOWN)
{
//Tools.WriteMessageWithReturn(e.Message.wParam.ToString());
OnKeyDown(e.Message.wParam.ToInt32());
}
}
}
获取的路径没有程序名称 第11行时,已取得成功。只是我故意做的过滤,只取路径 这样行不行
string _CodeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase
_CodeBase.Substring(0 , _CodeBase.LastIndexOf('\') ) 可能更好, Dim Mnetp As String = Microsoft.VisualBasic.Compatibility.VB6.Support.GetPath()
Dim Mnetn As String = Microsoft.VisualBasic.Compatibility.VB6.Support.GetEXEName()
simple and work well! Though old. 请问一下您是CAD200几的,我2008的好像不行!
页:
[1]