win mobile 启蓝牙 以及 重启系统 的API函数是什么?
2011-04-19 22:31
134 查看
希望实现两个功能:
1、 开启蓝牙,类似于进入bluetooth管理器去打开蓝牙。而我希望在程序中实现。
2、 系统重新启动功能,即重启win mobile。
C# code
[/code]
1、 开启蓝牙,类似于进入bluetooth管理器去打开蓝牙。而我希望在程序中实现。
2、 系统重新启动功能,即重启win mobile。
C# code
public struct TokPriv1Luid { public int Count; public long Luid; public int Attr; } [DllImport("kernel32.dll",ExactSpelling=true)] public static extern IntPtr GetCurrentProcess(); [DllImport("advapi32.dll",ExactSpelling=true,SetLastError=true)] public static extern bool OpenProcessToken(IntPtr h,int acc,ref IntPtr phtok ); [DllImport("advapi32.dll",SetLastError=true)] public static extern bool LookupPrivilegeValue(string host,string name,ref long pluid ); [DllImport("advapi32.dll",ExactSpelling=true, SetLastError=true) ] public static extern bool AdjustTokenPrivileges(IntPtr htok,bool disall, ref TokPriv1Luid newst,int len,IntPtr prev, IntPtr relen); [DllImport("user32.dll",ExactSpelling=true,SetLastError=true) ] public static extern bool ExitWindowsEx(int flg,int rea); public const int SE_PRIVILEGE_ENABLED = 0x00000002; // public const int TOKEN_QUERY = 0x00000008; // public const int TOKEN_ADJUST_PRIVILEGES = 0x00000020; // public const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";// public const int EWX_LOGOFF = 0x00000000; // 注消 public const int EWX_SHUTDOWN = 0x00000001; // 先保存再关机 public const int EWX_REBOOT = 0x00000002; // 重启 public const int EWX_FORCE = 0x00000004;//终止没响应程序 public const int EWX_POWEROFF = 0x00000008;//强制关机 public const int EWX_FORCEIFHUNG = 0x00000010;//不保存就关机 /// <summary> /// 关机,重启。。。。。 /// </summary> /// <param name="flg"></param> private void DoExitWin( int flg) { bool send; TokPriv1Luid tp; IntPtr hproc = GetCurrentProcess(); IntPtr htok = IntPtr.Zero; send = OpenProcessToken(hproc,TOKEN_ADJUST_PRIVILEGES |TOKEN_QUERY,ref htok ); tp.Count = 1; tp.Luid = 0; tp.Attr = SE_PRIVILEGE_ENABLED; send = LookupPrivilegeValue(null,SE_SHUTDOWN_NAME,ref tp.Luid); send= AdjustTokenPrivileges(htok,false,ref tp,0,IntPtr.Zero,IntPtr.Zero); send = ExitWindowsEx(flg,0); } /// <summary> /// 不保存关闭 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuItem9_Click(object sender, System.EventArgs e) { DoExitWin(EWX_FORCEIFHUNG); } /// <summary> /// 强制关闭 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuItem8_Click(object sender, System.EventArgs e) { DoExitWin(EWX_POWEROFF); }
[System.Runtime.InteropServices.DllImport("coredll")] public extern static int KernelIoControl(int dwIoControlCode, IntPtr lpInBuf, int nInBufSize, IntPtr lpOutBuf, int nOutBufSize, ref int lpBytesReturned);[System.Runtime.InteropServices.DllImport("coredll")] public extern static void keybd_event(byte bVK, byte bScan, byte dwFlags, byte dwExtraInfo);private void Shutdownbtn_Click() { int IOCTL_HAL_SHUTDOWN = 0x1012000; int bytesReturned = 0; byte VK_OFF = 0xdf; byte KEYEVENTF_KEYUP = 2; KernelIoControl(IOCTL_HAL_SHUTDOWN, IntPtr.Zero, 0, IntPtr.Zero, 0, ref bytesReturned); keybd_event(VK_OFF, 0, 0, 0); keybd_event(VK_OFF, 0, KEYEVENTF_KEYUP, 0);} //软重启: public const uint FILE_DEVICE_HAL = 0x00000101; public const uint METHOD_BUFFERED = 0; public const uint FILE_ANY_ACCESS = 0; public static uint CTL_CODE(uint DeviceType, uint Function, uint Method, uint Access) { return ((DeviceType << 16) | (Access << 14) | (Function << 2) | Method); } [System.Runtime.InteropServices.DllImport("Coredll.dll")] public extern static uint KernelIoControl ( uint dwIoControlCode, IntPtr lpInBuf, uint nInBufSize, IntPtr lpOutBuf, uint nOutBufSize, ref uint lpBytesReturned ); public static uint ResetPocketPC() { uint bytesReturned = 0; uint IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS); return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, ref bytesReturned); } 可以动态调用bthutil.Dll中的BthSetMode函数来找开启蓝牙 C/C++ code [code]enum BTH_RADIO_MODE { BTH_POWER_OFF, BTH_CONNECTABLE, BTH_DISCOVERABLE }; typedef int(*pBthSetMode)(DWORD); typedef int(*pBthGetMode)(DWORD*); HINSTANCE hModule = LoadLibrary (L"bthutil.Dll"); if(hModule != NULL) { pBthSetMode BthSetMode = (pBthSetMode) GetProcAddress(hModule, _T("BthSetMode")); pBthGetMode BthGetMode = (pBthGetMode) GetProcAddress(hModule, _T("BthGetMode")); if(BthSetMode != NULL && BthGetMode != NULL) { DWORD dwMode; int nRet = BthGetMode(&dwMode); if (dwMode == BTH_POWER_OFF || dwMode == BTH_CONNECTABLE) { BthSetMode(BTH_DISCOVERABLE); FreeLibrary(hModule); return TRUE; } } FreeLibrary(hModule);
蓝牙有三种状态: 1.关闭,BTH_POWER_OFF 2.开启,不可见 BTH_CONNECTABLE 3.开启,可见 BTH_DISCOVERABLE 获取蓝牙当前模式调用函数: int BthGetMode(DWORD *dwMode); 其中dwMode保存了蓝牙状态参数BTH_POWER_OFF,BTH_CONNECTABLE,BTH_DISCOVERABLE中的一个 设置蓝牙状态调用函数:int BthSetMode(DWORD dwMode); 比如开启蓝牙 BthSetMode(BTHCONNECTABLE); } return FALSE;
[/code]
相关文章推荐
- 老男孩教育每日一题-第86天-nfs客户端挂载信息写入/etc/fstab中,系统重启,没有自动挂载是什么原因?
- 流媒体系统包括哪三部分?目前三大主流媒体格式以及协议是什么?
- 解决找不到ifconfig命令,更改路径并重启系统后进入命令行界面以及各个命令无法执行Linux:-bash: ***: command not found
- 什么是API函数以及如何使用W7100A进行初始化(TCPIPCore)?(一)
- 什么是API函数以及如何使用W7100A进行初始化(TCPIPCore)?(二)
- vmware虚拟机重启。以及系统服务重启后的相关设置
- 嵌入式做驱动,做系统,以及做应用,分工有什么区别。
- android修改系统源码之实现蓝牙自动配对以及取消开机锁屏
- Linux操作系统:系统的关机、重启以及登出命令
- 下载系统镜像以及office软件什么的好地址
- Linux系统的关机、重启以及登出命令
- DELPHI中调用API函数ExitWindowsEX可以实现系统的关机,注销,和重启
- Linux操作系统:系统的关机、重启以及登出命令
- 什么是低耗蓝牙BLE以及与经典蓝牙的优劣
- 系统的关机、重启以及登
- Mac系统中mysql的启动 关闭 重启 以及kill进程不断重启的解决方案
- 程序锁定windows系统以及调用其它系统对话框,如控制面板,重启系统
- linux系统的关机、重启以及登出命令
- 什么是分布式系统!以及分布式系统架构的优缺点!
- windows提权操作以及系统开机关机重启代码(用到了LookupPrivilegeValue和AdjustTokenPrivileges调整进程的Token权限)