在VC运行环境下运用什么API函数可以得到操作系统所在的分区。比如操作系统WIN2000在C盘或D盘目录为WINNT,运用什么API函数可以返回出C:\WINNT或D:\WINNT
解决方案 »
- 修改完注册表之后,重新启动后,出现内存错误
- 100分求关于删除History文件夹的问题[在线等]
- 我有一个会动的gif图片,为什么用VB的PICTURE控件装起来之后,就不动了?
- 简单的问题,希望得到帮助。
- 請教這個問題
- 急,在线等,有关命令行参数的问题
- 请教:怎样把http://www.yp.net.cn/schinese/search/search.asp?SP=Tsl2X&key=%B9%AB%CB%BE&city=&province=6&IMGBT.x=22&IMGBT.y=11上名
- 如何用API控制打印队列中的内容???
- VB有个问题回答的详细点谢谢
- 一个很简单的问题 ???????在线等待
- msgbox的一个语法。请指点。(每个人都给分)
- 在线等,关于画线
GetSystemDirectory(szSysDir,MAX_PATH);
用此函数可得到如"c:\winnt\system32"之后可以分析字符串。
Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LonglpBuffer String,用于装载系统目录路径名的一个字串缓冲区。它应事先初始化成nSize+1个字符的长度。通常至少要为这个缓冲区分配MAX_PATH个字符的长度
nSize Long,lpBuffer字串的最大长度
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
得到Windows系统目录
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
得到临时文件存放目录
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
得到当前目录
Private Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectory" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
'Windows desktop virtual folder at the root of the name space
vbCSIDL_DESKTOP = &H0& 'File system directory that contains the
'user's program groups (which are also file 'system directories)
vbCSIDL_PROGRAMS = &H2&
'Control Panel - virtual folder containing
'icons for the control panel applications
vbCSIDL_CONTROLS = &H3&
'Printers folder - virtual folder containing 'installed printers.
vbCSIDL_PRINTERS = &H4& 'File system directory that serves as a
'common repository for documents (My Documents folder)
vbCSIDL_PERSONAL = &H5&
'File system directory that contains the
'user's favorite Internet Explorer URLs
vbCSIDL_FAVORITES = &H6&
'File system directory that corresponds to the
'user's Startup program group
vbCSIDL_STARTUP = &H7&
'File system directory that contains the
'user's most recently used documents (Recent folder)
vbCSIDL_RECENT = &H8& 'File system directory that contains
'Send To menu items Public Const
vbCSIDL_SENDTO = &H9&
'Recycle bin file system directory containing file
'objects in the user's recycle bin. The location of
'this directory is not in the registry; it is ed
'with the hidden and system attributes to prevent the
'user from moving or deleting it.
vbCSIDL_BITBUCKET = &HA&
'File system directory containing Start menu items
vbCSIDL_STARTMENU = &HB&
'File system directory used to physically store
'file objects on the desktop (not to be confused
'with the desktop folder itself).
vbCSIDL_DESKTOPDIRECTORY = &H10&
'My Computer - virtual folder containing everything
'on the local computer: storage devices, printers,
'and Control Panel. The folder may also contain 'mapped network drives.
vbCSIDL_DRIVES = &H11&
'Network Neighborhood - virtual folder representing
'the top level of the network hierarchy
vbCSIDL_NETWORK = &H12&
'File system directory containing objects that
'appear in the network neighborhood
vbCSIDL_NETHOOD = &H13&
'Virtual folder containing fonts
vbCSIDL_FONTS = &H14&
'File system directory that serves as a
'common repository for document templates '(ShellNew folder.)
vbCSIDL_TEMPLATES = &H15&
End Enum
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
(ByVal hWndOwner As Long, _
ByVal nFolder As SPECIAL_FOLDERS, _
pidl As Long) As Long'Converts an item identifier list to a file system path.
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long'This fuction is courtesy of Randy Birch and VBNet <www.mvps.org/vbnet>
'however I changed it a bit to fit my class
Private Function GetSpecialFolderLocation(CSIDL As SPECIAL_FOLDERS) As String Dim sPath As String
Dim pidl As Long
'fill the idl structure with the specified folder item
If SHGetSpecialFolderLocation(m_hWnd, CSIDL, pidl) = NOERROR Then
'if the pidl is returned, initialize
'and get the path from the id list
sPath = Space$(MAX_PATH)
If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then 'free the pidl and return the path
Call CoTaskMemFree(ByVal VarPtr(pidl))
GetSpecialFolderLocation = left(sPath, InStr(sPath, Chr$(0)) - 1)
End If
End If
End Function
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
Private Const NOERROR As Long = &H0////
上面是一个类模块中的函数, 稍加修改就可方便调用了, 可以获得一些常用的目录