当前位置:编程学习 > C#/ASP.NET >>

64位系统下调用user32.dll等文件效率的问题

客户要求在程序里加入全局键盘钩子并且程序窗口置顶。

于是加了如下代码



        // 設置掛鉤.

        // 安装钩子 (using System.Runtime.InteropServices;) 
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
        // 卸载钩子 
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern bool UnhookWindowsHookEx(int idHook);
        // 继续下一个钩子 
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int CallNextHookEx(int idHook, int nCode, Int32 wParam, IntPtr lParam);
        // 取得当前线程编号(线程钩子需要用到) 
        [DllImport("kernel32.dll")]
        static extern int GetCurrentThreadId();

   [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);



具体实现的方法就不贴了,因为就算不调用具体的方法, 程序的效率还是慢了将近一倍。
应该不是代码的问题。加这些之前没有问题。 我在本地32位系统测试速度也没有变化。
但是发给客户测试的时候,他的64位系统测试的时候转换速度就比之前没加这些代码的时候慢了一倍还多。
有没有高手知道这是何故!
PS:这是一个视频转图片的软件。

补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,