WINDOWS未开函数揭密
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
WINDOWS未开函数揭密
什么是未公开函数?
对于Windows的API函数调用相信大家已经不会陌生了。API函数调用是通过在VB中定义和调用Windows动态连接库中的函数从而扩展VB程序的功能。API函数的定义和调用方法在微软的开发工具中都有详细的说明。
那么什么是“未公开”函数呢?微软为了某种目的。对于一些封装在系统中的函数没有在任何开发文档提供任何函数说明和定义。而这些函数有很多都是很有用的。所幸的是一些有心之人对Windows系统动态连接库做了十分详细的分析,从而将这些未公开函数公开以供广大开发人员共享(我对他们的感激之情就象滔滔江水,绵绵不绝……)
好了,废话少说,言归正传,这里首先向大家介绍的是Windows下未公开的关闭Windows的函数。在Windows API函数中虽然提供了ExitWindowsEx这样的API函数,但是在有一些程序中我们需要象一些程序安装完毕那样提示用户重新启动计算机或者不重新启动计算机。或者要在程序中弹出关闭系统对话框。要实现这些功能就要使用Windows未公开函数了。下面来看程序。
首先建立一个新的工程文件,在工程文件中加入一个Module文件。在Module文件中加入以下代码:Option Explicit
Public bIsWinNT As Boolean
'下面就是未公开的函数定义,注意在Alias之后没有使用函数的真正名字
'而是用了函数编号,这是因为微软没有公开函数名
Declare Function SHRestartSystemMB Lib“shell32"-
Alias “#59"-
(ByVal hOwner As Long, —
ByVal sExtraPrompt As String,-
ByVal uFlags As Long) As Long
Declare Function SHShutDownDialog Lib “shell32" -
Alias “#60" -
(ByVal YourGuess As Long) As Long
Declare Function GetVersionEx Lib “kernel32" -
Alias“GetVersionExA" -
(lpVersionInformation As OSVERSIONINFO) As Long Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String *128
End Type
Public Const EWX-LOGOFF = 0
Public Const EWX-SHUTDOWN = 1
Public Const EWX-REBOOT = 2
Public Const EWX-FORCE = 4
Public Const EWX-POWEROFF = 8
Public Const shrsExitNoDefPrompt = 1
Public Const shrsRebootSystem = 2
Const VER-PLATFORM-WIN32s = 0
Const VER-PLATFORM-WIN32-WINDOWS = 1 Const VER-PLATFORM-WIN32-NT = 2
Declare Sub CopyMemory Lib “kernel32"
Alias “RtlMoveMemory" -
(pDest As Any, -
pSource As Any, -
ByVal ByteLen As Long)
Declare Function IsTextUnicode Lib “advapi32"-(lpBuffer As Any,-
ByVal cb As Long, -
lpi As Long) As Long
Public Const IS-TEXT-UNICODE-ASCII16 = &H1
Public Const IS-TEXT-UNICODE-REVERSE-ASCII16 = &H10
Public Const IS-TEXT-UNICODE-STATISTICS = &H2
Public Const IS-TEXT-UNICODE-REVERSE-STATISTICS = &H20 Public Const IS-TEXT-UNICODE-CONTROLS = &H4
Public Const IS-TEXT-UNICODE-REVERSE-CONTROLS = &H40 Public Const IS-TEXT-UNICODE-SIGNATURE = &H8
Public Const IS-TEXT-UNICODE-REVERSE-SIGNATURE = &H80 Public Const IS-TEXT-UNICODE-ILLEGAL-CHARS = &H100
Public Const IS-TEXT-UNICODE-ODD-LENGTH = &H200
Public Const IS-TEXT-UNICODE-DBCS_LEADBYTE = &H400
Public Const IS-TEXT-UNICODE-NULL-BYTES = &H1000
Public Const IS-TEXT-UNICODE-UNICODE-MASK = &HF
Public Const IS-TEXT-UNICODE-REVERSE-MASK = &HF0
Public Const IS-TEXT-UNICODE-NOT-UNICODE-MASK = &HF00 Public Const IS-TEXT-UNICODE-NOT-ASCII_MASK = &HF000
Public Function IsWinNT() As Boolean
Dim osvi As OSVERSIONINFO
osvi.dwOSVersionInfoSize = Len(osvi)
GetVersionEx osvi
IsWinNT = (osvi.dwPlatformId = VER-PLATFORM-WIN32-NT)
End Function
Public Function CheckString(msg As String) As String
If bIsWinNT Then
CheckString = StrConv(msg, vbUnicode)
Else: CheckString = msg
End If
End Function
Public Function GetStrFromPtr(lpszStr As Long, nBytes As Integer) As String ReDim ab(nBytes) As Byte
CopyMemory ab(0), ByVal lpszStr, nBytes